How to make variables mandatory or readonly if sc_task state will move cancell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi Everyone,
I need some guidance on a ServiceNow requirement.
When the SC Task (sc_task) state changes to Cancelled, I want to make certain catalog variables either mandatory or read-only.
What is the best way to achieve this? Should I use a Catalog Client Script, UI Policy, Business Rule, or another approach?
Any suggestions or examples would be appreciated. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
48m ago
Hi @Santosh Oraon ,
you can create UI policy or onChange client script on the state filed on the catalog task table since catalog client script will not be having the state as variable go with UI policy or onChange client script on the table(catalog task)
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
37m ago - last edited 36m ago
Hi @Chaitanya ILCR , could you please tell how to get variables in ui policy?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
31m ago
1) Try with this:
Create a new onChange Client Script with these configurations:
- Type: onChange
- UI Type: All
- Field name: state
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var cat = g_form.getValue('request_item.cat_item');
if (cat == '4a75538f0aaf39sdhjsdg9888e4fb76e') // your catalog item sys_id
{
// Replace '4' with your instance's exact 'Cancelled' state choice value if different
if (newValue === '4') {
// 1. Making certain variables Mandatory
// Here instead of variables. your_variable_name_1 , if you use only your_variable_name_1 that will also work
g_form.setMandatory('variables.your_variable_name_1', true);
g_form.setMandatory('variables.your_variable_name_2', true);
// 2. Making certain variables Read-Only
g_form.setReadOnly('variables.your_variable_name_3', true);
g_form.setReadOnly('variables.your_variable_name_4', true);
} else {
// Optional: Revert settings if the state is changed away from Cancelled
g_form.setMandatory('variables.your_variable_name_1', false);
g_form.setMandatory('variables.your_variable_name_2', false);
g_form.setReadOnly('variables.your_variable_name_3', false);
g_form.setReadOnly('variables.your_variable_name_4', false);
}
}
}
2) check this as well :https://www.servicenow.com/community/developer-forum/how-to-make-a-field-mandatory-only-on-sc-task-f...
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti