Making catalog task variable mandatory in the sctask form based on sc_task state and another variabl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2024 05:10 PM
Could you please help me to make a variable mandatory in the sc_task form based on sc_task state and another varaible
Please help....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2024 06:02 PM
Hi @JPSS ,
you use ui policy to make variable mandatory. Put the condition under when to apply like state is new or work in progress.
Accept the solution if it helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2024 06:12 PM
i tired below code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2024 07:27 PM
This not ServiceNow code which you have written.
create ui policy instead of writing code.
add condition state is new or choose state on which you want to make field mandatory.
Apply ui policy action and choose your variable to make mandatory.
Visit here , I have explained it step by steps
https://servicenowwithrunjay.com/ui-policy-in-servicenow/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2024 02:53 AM
Since you want to include a field on the sc_task table and a variable in the Catalog Item, be sure your UI Policy is on the sc_task table, not a Catalog UI Policy in the Catalog Item. Your script should look more like this:
function onCondition() {
if (g_form.getValue('system_do_you_need_help_with') == "Optimus")
g_form.addErrorMessage('error');
g_form.setMandatory('close_category_closed_skipped', true);
g_form.setVisible('close_category_closed_skipped', true);
}
}
You might find that the error message remains even when it shouldn't. If that's an issue, consider using an alert instead, or add a check in either the Execute if true and/or Execute if false scripts to g_form.clearMessages() if conditions are met. Another perhaps more straightforward approach is to instead use a Client Script on the sc_task table with similar code wrapped in an if statement that is checking the State value.