- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2024 10:16 AM
Hello Experts,
I have written below to calculate the difference between the two dates can anyone why my script is not working?
Thank You.
Display Business Rule
var gd1=new GlideDateTime();
gd1.setDisplayValue(current.sys_created_on);
var gd2=new GlideDateTime();
gd2.setDisplayValue(current.sys_created_on);
var duration=GlideDateTime.subtract(gd1.gd2);
g_scratchpad.diff=duration.getDisplayValue();
Onload Client Script:
function onLoad()
{
var d=g_scratchpad.diff;
alert(d);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2024 10:58 AM - edited ‎03-24-2024 10:59 AM
Hi @Mark Wood ,
There are few errors please correct it,
1. you are checking the difference between same field sys_created_on so change the second field backend name,
2.in subtract it should be (gd2 , gd1) it should be ,(comma) not .(full stop)
i have modified the code please check,
BR
(function executeRule(current, previous /*null when async*/ ) {
var gd1 = new GlideDateTime(current.sys_created_on);
var gd2 = new GlideDateTime(current.sys_updated_on);
var duration = GlideDateTime.subtract(gd2, gd1);
g_scratchpad.diff = duration.getDisplayValue();
})(current, previous);
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2024 10:58 AM - edited ‎03-24-2024 10:59 AM
Hi @Mark Wood ,
There are few errors please correct it,
1. you are checking the difference between same field sys_created_on so change the second field backend name,
2.in subtract it should be (gd2 , gd1) it should be ,(comma) not .(full stop)
i have modified the code please check,
BR
(function executeRule(current, previous /*null when async*/ ) {
var gd1 = new GlideDateTime(current.sys_created_on);
var gd2 = new GlideDateTime(current.sys_updated_on);
var duration = GlideDateTime.subtract(gd2, gd1);
g_scratchpad.diff = duration.getDisplayValue();
})(current, previous);
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2024 01:09 AM
@Mark Wood Thanks for marking my answer as helpful. If it helped you in any way please accept the solution so that it will be beneficial to the future readers with the same query
Thanks,
Swathi