- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 12:33 AM
How to get Due Date and Current Date Difference using BR? I have a scenario where I have a need to get Difference of current date and due date and need to publish via report. I need to show difference in days only. Should I use client script instead of BR?
I tried this :
var date=new GlideDate();
var current=date;
gs.info(current) //Showing me the current Date
var gr=new GlideRecord('table_name');
var dd=gr.getValue('due_date'); or var dd=gr.getDisplayValue('due_date');
var diff=dd-current;
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2022 05:07 AM
Hi
this script will work in scoped app and give the difference in days
Note: If you wish to populate the difference in some field when BR runs; the BR should be Before and not After
var currentTime = new GlideDateTime();
var actualDatetime = new GlideDateTime(current.due_date);
var dur = new GlideDuration();
dur = GlideDateTime.subtract(currentTime, actualDatetime);
var days = dur.getDayPart();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2022 06:56 PM
Hi
Glad to know that my script worked.
I believe I have given you the right direction to proceed which you can enhance further as per your requirement. I have shared solution to your original question asked.
Please mark my response as correct and close the thread.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 05:06 AM
Hi Ankur,
This code is giving me the proper output with calculated field, but calculated field is not doing the calculation on daily bases.
I) Is there any way to run this dictionary(calculated field ) on every page load. Can I use a schedule job for this if yes then how?
II)This calculated result is coming right in list view and list report as well, but in Multiple Pivot this result is coming as empty for all.
III)function field is also not supporting my requirement. At past I raised a ServiceNow Hi ticket for this why calculated field data is coming in multiple pivot report. Is this a limitation?
They suggested me to use function field instead of calculated field but that is also not giving me the right result and they told me this is new finding function field is not supporting your requirement and they will improve this in upcoming releases.
IV) How I can completed this requirement. Should I use business rule with schedule job b/s calculation should be change on daily bases can not be constant?
I need to fulfil this requirement asap. Please suggest me the best approach to fulfill this requirement.