- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 10:47 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 12:30 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2023 09:09 PM
Please post a new question as the original question is answered and tag me there.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader