Make Work notes or Additional comments required upon closure with client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2019 09:45 AM
All,
I'm attempting to build a client script that requires either work notes or additional comments be populated upon closure of a catalog task. We have added additional comments to the sc_task form as a reference to sc_req_item.comments. The script below is not working.
function onChange(control, oldValue, newValue) {
if (oldValue == newValue)
return;
var state = g_form.getValue('state');
var cmnts = g_form.getValue('sc_req_item.comments');
if (state == '3' || state == '4' || state == '7' && cmnts == ''){
g_form.setMandatory('work_notes', true);
g_form.setMandatory('assigned_to', true);
}
else {
g_form.setMandatory('work_notes', false);
g_form.setMandatory('comments', true);
g_form.setMandatory('assigned_to', true);
}
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2019 09:57 AM
Hi there,
What exactly is not working? Have you checked if the script is executed at all? Maybe the UI Type is already an issue. Or onChange of what field is this running? I guess State?
Looking at your script:
g_form.getValue('sc_req_item.comments'); will not work for sure. Also consider changing state == '3' || state == '4' || state == '7', the state don't need quotes, these are integers, or just check is active is true/false.
Also var state = g_form.getValue('state'); could also just use newValue?
If you would fix this, it should be able to work.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2019 10:28 AM
Thanks for your response Mark.
I should've added in my initial post:
UI Type: All
Type: OnChange
Field Name:State
The script continues to mark work_notes and assigned_to as a mandatory fields, ignoring the criteria of the comments field. I wouldn't think I would need a getReference back to the ritm as I am not submitting this journal field until I successfully submit the record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2019 10:47 AM
So g_form.getValue('sc_req_item.comments'); is your issue indeed.
Its simply because dotwalking this way is not possible client side. You could do a getReference, though far more better would be GlideAjax with a getXMLAswer.
If you would fix this, it should be able to work.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field