Get Date difference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2017 04:09 AM
Hello, I would like to get a date difference in days between a Date field an Today date in Business Rule in scoped app.
It try this:
var start = current.startdate;
gs.addInfoMessage(start);
var today = new GlideDate();//.getDisplayValue();
gs.addInfoMessage(today);
var diff = gs.dateDiff(start, today, true);
gs.addInfoMessage(diff);
I get the error: Function dateDiff is not allowed in scope x_63963_cognizant. Use GlideDateTime.subtract() instead
If I use the line: var diff = GlideDateTime.subtract(start, today);
OR just GlideDate
I also get an error, object GlideDateTime not found.
Could you help me please how get this? All I need is a number value in days between the stardate field and the current date.
Many thanks!
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2017 04:17 AM
Hi Laszlo,
Following links will be helpful to you:
Scoped GlideDateTime API Reference - ServiceNow Wiki
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
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
05-25-2017 04:34 AM
Hi Laszlo,
Could you please try the below one:
var start = current.startdate;
var gdt1 = new GlideDateTime();
gdt1.setDisplayValue(start);
var today = new GlideDate().getDisplayValue();
var dur = new GlideDuration();
dur = GlideDateTime.subtract(today,gdt1).getDayPart();
gs.info(dur);
I hope this helps. Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2017 01:28 AM
Hi Laszlo,
Did you get code for your solution,
If yes can you please share , i am also looking for this type of code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2017 01:57 AM
Hi Laszlo,
Try this:
(function executeRule(current, previous /*null when async*/) {
var gdStartDate = new GlideDate();
var gdEndDate = new GlideDate();
gdEndDate.setValue(current.your_date_field);
current.date_diff_in_days = GlideDate.subtract(gdStartDate, gdEndDate).getDayPart();
})(current, previous);
Regards
Greg