- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2025 05:14 AM
Hi All
After submitting the catalog item I want to make a variable set mandatory in sc_req_item table workspace only when state choice is changes to closed complete. I have tried on change client script as well but the field name cant be state in catalog item. Can someone help on this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2025 11:40 AM
In this example, 'state' is undefined. Since this is running onChange of the State field, you can use newValue to retrieve the value of the state field. Also, you'll want to include an else block so that the variable remains not mandatory if the user switched to the Closed Complete State then another State before saving the record. The variable.variableName syntax is optional and can be simplified to just use the variable name:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var variableValue = g_form.getValue('variableName');
if (variableValue == '' && newValue == 3) {
g_form.setMandatory('variableName', true);
} else {
g_form.setMandatory('variableName', false);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2025 07:00 PM
small mistake in my script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var variableValue = g_form.getValue('variables.variableName');
if (variableValue == '' && g_form.getValue('state') == 3) {
g_form.setMandatory('variables.variableName', true);
}
}
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
‎02-10-2025 05:52 AM
You can do this with a Client Script (not Catalog) that applies to the sc_req_item table, not the Catalog Item. Use g_form methods with the name of the RITM field or Catalog Item variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2025 06:08 AM
Agree with Brad.
It should be onChange client script on State field and simply check if variable is populated
If not then make it mandatory
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var variableValue = g_form.getValue('variables.variableName');
if (variableValue == '' && state == 3) {
g_form.setMandatory('variables.variableName', true);
}
}
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
‎02-10-2025 06:53 AM
Hi @Ankur Bawiskar its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2025 07:00 AM