- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2016 03:09 PM
I'd like to force a variable to be mandatory on my catalog task to be mandatory when the catalog task form is being submitted AND state = closed complete (3).
I tried doing this with a business rule, and it sort of works.. but the "Close Complete" UI action bypasses it as it forces a redirect and this apparently doesn't work in conjunction with .setAbortAction.Trying to look for some alternatives as I would like the entire page to stop loading/redirecting when using the Close Complete button, or setting to Closed Complete manually, and make the variable mandatory:
- (function executeRule(current, previous /*null when async*/) {
- if(current.variables.offboard_desktoprecoverassets == '' && current.state == "3"){
- current.state=previous.state;
- current.setAbortAction(true);
- gs.addInfoMessage('NOTICE: Please select an option for desktop recovery below completing the task.');
- gs.setRedirect(current);
- }
- })(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2016 05:01 PM
You can write a onSubmit client script and put this script in there
function onSubmit() {
var ritm= g_form.getReferenec("request_item");
if((g_form.getValue('state')==3) && (ritm.cat_item=='Your cat item sys_id')){
if(g_form.getValue('variables.<variable_name>')==''){
g_form.setMandatory('variables.<variable_name>',true);
return false;
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2016 03:17 PM
Hi Shane,
The best option is to create a UI policy and make field mandatory as per the conditions you have mentioned via filter. Please refer below link for more info.
Creating a UI Policy - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2016 03:32 PM
Can I have this be a UI Policy on the catalog item, rather than directly on the catalog task form? This requirement is only specific to this catalog item...
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2016 03:37 PM
Thanks Shane for the update. Yes you can have this specific to catalog item. But is the req to make mandatory on catalog item or catalog task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2016 03:44 PM
The catalog UI policy is to only apply on the catalog task, that is generated by the catalog item's workflow.
I have only "Applies on Catalog Tasks" checkes, so to only run on the catalog task level, but I can not use the filter to choose a record attribute like "State" or "Date opened", etc, it will only give me variables to condition the UI policy off of. Under advanced scripting, I only see an option to script what happens on the condition, now how to script a custom condition.