- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 05:25 AM
Hi All,
There is a planned due date (date/ time) field on my incident form.
I want whenever user tries to create incident task from related list, planned due date (date) field on incident task should auto populate date that was on incident.
I have written display business rule on incident task to get date from parent incident-
(function executeRule(current, previous /*null when async*/) {
var inc= new GlideRecord('incident');
if(inc.get(current.incident))
var plannedDate = new GlideDateTime(inc.due_date);
g_scratchpad.plannedDueDate = plannedDate.getDate();
})(current, previous);
Then, I've written onload client script on incident task -
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('incident'))
var plannedDate = g_scratchpad.plannedDueDate;
g_form.setValue('u_planned_due_date', plannedDate);
}
But instead of setting date, it shows object object
Can someone please help me on what Im doing wrong in above script?
Thanks in Advance!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 05:32 AM
simply set that from display business rule and don't use client script
(function executeRule(current, previous /*null when async*/) {
var inc= new GlideRecord('incident');
if(inc.get(current.incident)){
current.setValue('u_planned_due_date',new GlideDateTime(inc.due_date));
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 05:33 AM
if you want to use both then do this
Display business rule:
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
if (inc.get(current.incident)) {
var plannedDate = new GlideDateTime(inc.due_date);
g_scratchpad.plannedDueDate = plannedDate.getDisplayValue(); // Use getDisplayValue() to get the date as a string
}
})(current, previous);
Client script:
function onLoad() {
if (g_form.getValue('incident')) {
var plannedDate = g_scratchpad.plannedDueDate;
g_form.setValue('u_planned_due_date', plannedDate);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 05:32 AM
simply set that from display business rule and don't use client script
(function executeRule(current, previous /*null when async*/) {
var inc= new GlideRecord('incident');
if(inc.get(current.incident)){
current.setValue('u_planned_due_date',new GlideDateTime(inc.due_date));
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 05:33 AM
if you want to use both then do this
Display business rule:
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
if (inc.get(current.incident)) {
var plannedDate = new GlideDateTime(inc.due_date);
g_scratchpad.plannedDueDate = plannedDate.getDisplayValue(); // Use getDisplayValue() to get the date as a string
}
})(current, previous);
Client script:
function onLoad() {
if (g_form.getValue('incident')) {
var plannedDate = g_scratchpad.plannedDueDate;
g_form.setValue('u_planned_due_date', plannedDate);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 05:41 AM
Thanks @Ankur Bawiskar , Instead of writing additional client script, I'll use br only.
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 05:56 AM
Glad to help.
Would you mind closing your earlier questions by marking appropriate response as correct?
Members have invested their time and efforts in helping you.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader