UI Only formula field to add days to a date

  • 3
  • Question
  • Updated 5 months ago
  • Answered
Hey! I want to add certain number of days to a date using UI only formula field in skuid. But I'm unable to achieve this in Skuid. Is there any other solution for this??
Photo of V Chinmay Nandini

V Chinmay Nandini

  • 92 Points 75 badge 2x thumb

Posted 2 years ago

  • 3
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 18,336 Points 10k badge 2x thumb
This post gives an example of working with dates in a UI only that you can use as a template

https://community.skuid.com/skuid/top...
Photo of Bill McCullough

Bill McCullough, Champion

  • 13,612 Points 10k badge 2x thumb
V Chinmay,

I don't think there is a way to use a UI formula field to add days to a date.  Depending upon your needs,  I would add a custom formula field in Salesforce that will return a date so many days in the future.  If you need the future date as part of the Skuid page, then you'll need to do this with a Snippet.

Thanks,

Bill
Photo of Bill McCullough

Bill McCullough, Champion

  • 13,612 Points 10k badge 2x thumb
Skuid Community,

I needed this myself.  Here is the code for a Custom Formula Field function to add days to a date field:

skuid.formula.Formula (
  'ADD_DAYS',
  function (fieldName, daysToAdd) {
      if(fieldName !== null && fieldName !== undefined ) {
      if(daysToAdd===null || daysToAdd===undefined || daysToAdd==='') {
      daysToAdd = 0;
      }
    var jsDate = skuid.time.parseSFDate(fieldName);
    //add days
    jsDate.setDate(jsDate.getDate() + daysToAdd);
    //convert from Javascript date back to Salesforce date
        return skuid.time.getSFDate(jsDate);
    } else {
        return null;
    }
  },{
    namespace: 'dateFunctions',
    numArgs : 2,
    returnType : 'date'
  }
);
//
// Usage
// dateFunctions__ADD_DAYS({{Date_Field__c}}, 30)
// dateFunctions__ADD_DAYS({{Date_Field__c}}, {{daysToAdd}})
//
// Where'
// {{Date_Field__c}} is a field of type = DATE
// {{daysToAdd}} is a NUMBER or TEXT field represting the number of days to add

Thanks,

Bill
Photo of Mansour

Mansour

  • 2,250 Points 2k badge 2x thumb
Thank you Bill!