- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2019 06:46 AM
Hi Everyone,
My incident module is in scoped application and SLA record is in global scope
I am looking for below difference
Date = Incident created date - Incident Resolved Date
Date1 = Incident SLA Paused duration date
Final Date = Date - Date1 (Final date field to be created on incident form)
Can someone help me on this task please ? Thank you in advance
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2019 07:33 PM
Hi,
Your these two lines need to correct.
var t = new GlideDateTime(dur).getDisplayValue();
var f= new GlideDateTime(pauseDur).getDisplayValue();
just remove getDisplayValue() it will work.
Thanks,
Dhananjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2019 08:35 AM
Hello,
dateDiff() method is not allowed in scoped applications,
Please refer below link,It might be help you out.
dateDiff() methttps://community.servicenow.com/community?id=community_question&sys_id=5ddc4b75db0c770013b5fb243996198bhod is not allowed in scohttps://community.servicenow.com/community?id=community_question&sys_id=5ddc4b75db0c770013b5fb243996198bped applications. Instead you can use:
Please mark as correct and Helpful,If you find any help worthy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2019 06:59 PM
Hi Kajal,
Please find the below code, written on before business rule and am getting below error. Please assist me with this code. Thank you.
"Error running business rule 'x_novrp_active duration calculation' on x_premier_it_inc:PRINC1196891, exception: org.mozilla.javascript.EvaluatorException: Can't find method com.glide.script.fencing.ScopedGlideDateTime.subtract(string,string). (sys_script.052d2e36db3dcc107aa54baf16961906.script; line 30)"
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var pauseDur;
var task_sla = new GlideRecord('task_sla');
task_sla.addQuery('task', current.sys_id);
task_sla.addQuery('stage', 'paused');
task_sla.query();
while (task_sla.next()){
pauseDur = task_sla.pause_duration.getDisplayValue();
//gs.addInfoMessage("from SLA = "+pauseDur);
}
var currentDate = current.opened_at.getDisplayValue();
var resolvedDate = current.resolved_at.getDisplayValue();
var date = GlideDateTime(currentDate);
var date1 = GlideDateTime(resolvedDate);
var dur = GlideDateTime.subtract(date, date1);
var t = new GlideDateTime(dur).getDisplayValue();
var f= new GlideDateTime(pauseDur).getDisplayValue();
//gs.addInfoMessage(gs.getMessage(dur.getDisplayValue()));
//gs.info('123456789=='+currentDate.getDisplayValue());
var finalDur = GlideDateTime.subtract(t ,f);
//gs.info("34536456456567567567567final duration ="+finalDur);
current.active_duration = finalDur.getDisplayVlaue();
//gs.addInfoMessage(current.active_duration);
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2019 07:33 PM
Hi,
Your these two lines need to correct.
var t = new GlideDateTime(dur).getDisplayValue();
var f= new GlideDateTime(pauseDur).getDisplayValue();
just remove getDisplayValue() it will work.
Thanks,
Dhananjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2019 09:45 PM
Hi Gowtham,
Don't worry about scope application if you want to use dateDiff().
You can write your script include in global scope and call it from client script of your scope application.
In that script include you can use dateDiff() function easily. But please don't forget to make Accessible from field to "All Application scope".
Please Mark as Correct/Helpful on impact.
Regards,
Meghnath.