- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 04:26 AM
Hi All,
I have to auto populate a date time field(due date) in problem Task form when the short description is "RCA" .The date should be current day + 10 Business days.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 08:23 AM
okay. what i understand is you want to set the short description and due date both when you are going to create a PR, in that case after Insert BR should help, please check if this helps.
(function executeRule(current, previous /*null when async*/) {
// Add your code herevar gdt = new GlideDateTime();
var gdt = new GlideDateTime();
if(gdt.getDayOfWeekLocalTime() == 6)
gdt.addDaysLocalTime(13);
else if(gdt.getDayOfWeekLocalTime() == 7)
gdt.addDaysLocalTime(12);
else //else add 14 days
gdt.addDaysLocalTime(14);
current.due_date = gdt.getDisplayValue();
current.short_description = 'Root Cause Analysis';
})(current, previous);
with the condition given like when the priority is high in condition builder:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 04:39 AM
Have you seen this
https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_reference/GlideDateTime/concept/c_GlideDateTimeAPI.html#ariaid-title4

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 05:16 AM
You can create a onChange() Client script on short description field to check if it has RCA text then make the GlideAjax call to add number of days. Please check if this helps.
Onchange()
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue.match(/RCA/g).length == 1){
var gr = new GlideAjax('MyDateTimeAjax');
gr.addParam('sysparm_name', 'setBusinessDays');
gr.getXML(ajaxResponse);
}
function ajaxResponse(serverResponse) {
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_due_date', answer);
}
}
Client callable Script Include:
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
setBusinessDays: function () {
var gdt = new GlideDateTime();
if(gdt.getDayOfWeekLocalTime() == 6)
gdt.addDaysLocalTime(13);
else if(gdt.getDayOfWeekLocalTime() == 7)
gdt.addDaysLocalTime(12);
else
gdt.addDaysLocalTime(14);
return gdt.getDisplayValue();
},
type: 'MyDateTimeAjax'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 06:02 AM
Thanks Shishir..
It is not working 😞

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 10:31 AM
Can you please share the screen and also can you please confirm if RCA keyword would be added when you are going to create the PR ?