- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 11:12 AM
I am attempting to generate a warning message in the 'On hold reason' field when an incident form meets this criteria prior to saving:
- Caller= Event Management
- State= On Hold
- On hold reason= Awaiting Caller
I'm new to SMV development work and struggle with scripting. I felt like the below code was going to work but it's not generating the message. I appreciate an feedback on this, details below.
Mock up of the intended functionality:
Client UI script settings:
Current code:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 09:04 PM
Hi @CesarV_
You can acheive this by creating one UI policy on the Incident table. PFB.
UI policy:
If you want to show that warning message only on the field changes, then uncheck the "on load" check box.
Else, if you want to show that whenever the condition statifies, then check the "On load" check box.
UI policy script:
function onCondition() {
g_form.showErrorBox("hold_reason", "Warning: Incident is Awaiting Caller for Event Management. Please select different On hold reason");
}
Output:
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 10:13 PM
you should create normal client script i.e. onSubmit on incident table and not catalog client script
function onSubmit() {
// Get the values of the fields
var caller = g_form.getValue('caller_id');
var state = g_form.getValue('state').toString();
var onHoldReason = g_form.getValue('hold_reason').toString();
// Check if the conditions are met
if (caller == 'eventManagementUserSysId' && state == '3' && onHoldReason == '1') {
// Generate a warning message
g_form.showFieldMsg("hold_reason", "Warning: Incident is Awaiting Caller for Event Management. Please select different On hold reason", "error");
return false; // Prevent the form from being submitted
}
return true; // Allow the form to be submitted
}
OR
You can use UI Policy for this as per @J Siva
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
04-23-2025 09:04 PM
Hi @CesarV_
You can acheive this by creating one UI policy on the Incident table. PFB.
UI policy:
If you want to show that warning message only on the field changes, then uncheck the "on load" check box.
Else, if you want to show that whenever the condition statifies, then check the "On load" check box.
UI policy script:
function onCondition() {
g_form.showErrorBox("hold_reason", "Warning: Incident is Awaiting Caller for Event Management. Please select different On hold reason");
}
Output:
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 07:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 09:10 AM
Great 👍.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 10:13 PM
you should create normal client script i.e. onSubmit on incident table and not catalog client script
function onSubmit() {
// Get the values of the fields
var caller = g_form.getValue('caller_id');
var state = g_form.getValue('state').toString();
var onHoldReason = g_form.getValue('hold_reason').toString();
// Check if the conditions are met
if (caller == 'eventManagementUserSysId' && state == '3' && onHoldReason == '1') {
// Generate a warning message
g_form.showFieldMsg("hold_reason", "Warning: Incident is Awaiting Caller for Event Management. Please select different On hold reason", "error");
return false; // Prevent the form from being submitted
}
return true; // Allow the form to be submitted
}
OR
You can use UI Policy for this as per @J Siva
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