- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 01:54 PM
I am very new to ServiceNow and was wondering if someone can help me. I would like to make work notes a required field when an Incident is re-assigned to another group. I would like to stop the incident from getting re-assigned until the work notes has been filled out. I went to client script and added the following script below. When I test it, the message "Please Add Work Notes When Reassigning" comes up however the incident still gets re-assigned to the group. I need to stop it from getting re-assigned without notes. Can someone help me fix the code?
NOTE: I am trying to achieve a similar result when a required field is not filled out. The incident should stay with the user until that requirement is fulfilled before it goes away.
Thank you!!
Here is the code I used:
function onSubmit(control, oldValue, newValue, isLoading, isTemplate) {
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 04:03 PM
Hi @Midori_Cakes ,
You can write an Onchange client script on assignment group
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var assignment_group = g_form.getValue('assignment_group');
if (assignment_group !== '' && oldValue !== newValue) {
g_form.setMandatory('work_notes', true);
}
}
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 07:51 PM
If you are using onSubmit client script, then onSubmit client script runs when the form is submitted, but it doesn't directly prevent the form submission, you need to return false as well, below is the modified script:
function onSubmit() {
// Check if work notes field is empty
if (g_form.getValue('work_notes') === '') {
// Display error message
g_form.addErrorMessage("Please Add Work Notes When Reassigning");
// Cancel form submission
return false;
}
// If work notes are filled out, allow form submission
return true;
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 08:34 PM
You need to make use of an On-Change Client Script on your Assignment Group field. Whenever the Assignment Group field will change and it is not empty, work notes field will be made mandatory. Refer below On-Change Client Script and try :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Get the current value of the Assignment Group
var assignmentGroup = g_form.getValue('assignment_group');
// Check if the Assignment Group field is not empty and the value changed
if (assignmentGroup !== '' && oldValue !== newValue) {
g_form.setMandatory('work_notes', true);
}
}
Output :
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 08:34 PM
You need to make use of an On-Change Client Script on your Assignment Group field. Whenever the Assignment Group field will change and it is not empty, work notes field will be made mandatory. Refer below On-Change Client Script and try :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Get the current value of the Assignment Group
var assignmentGroup = g_form.getValue('assignment_group');
// Check if the Assignment Group field is not empty and the value changed
if (assignmentGroup !== '' && oldValue !== newValue) {
g_form.setMandatory('work_notes', true);
}
}
Output :
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 07:03 AM
Thank you so much! I didnt realize I can do things multiple ways. Part of the learning process I guess. I appreciate your time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 07:01 AM
Thank you so much for everyone's help. Each of your solution worked as expected. I really appreciate this community 🙂