find the difference in dates and display the value in the field in the table.

Priya Rao
Tera Contributor

Hi All,

I have a requirement. Based on some trigger conditions, we need to submit a catalog item request. This is done using he subflow and business rules and it's working as expected. 

So now, in the table that we're using for trigger conditions, there's a field 'start_date' and 'end_date'. Based on that dates, when the catalog item request is auto-submitted, we need to calculate the difference in the days (end_date - start_date)

If start_date is 20/09/2023 and end_date is 25/09/2023, the difference should be 5 and this value should be filled in the field 'date_difference'  in the table. This should happen only when the RITM is raised.

How can I achieve this, please let me know.

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Priya Rao 

you can use before insert/update business rule

Use correct field names.

var start = new GlideDateTime(current.start_date);
var end = new GlideDateTime(current.end_date);
var dur = new GlideDuration();
dur = GlideDateTime.subtract(start, end);

var daysPart = dur.getDayPart();
current.fieldName = daysPart;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

@Priya Rao 

Please post a new question as the original question is answered and tag me there.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader