- 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-29-2016 02:20 PM
current.state = 3;
current.update();
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2016 02:32 PM
Use both client side and server side in the Ui action.Check the client checkbox in the Ui action and put runClientCode(); in the onClick of UI action and give the Ui action an action name. Copy this script in there
Client & Server Code in One UI Action - ServiceNow Guru
function runClientCode(){
var ritm= g_form.getReference("request_item");
if(ritm.cat_item=='Your cat item sys_id'){
if(g_form.getValue('variables.<variable_name>')==''){
g_form.setMandatory('variables.<variable_name>',true);
return false; //Abort submission
}
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), '<button_action_name>'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode(){
current.state = 3;
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2016 02:40 PM
A question regarding this change to the UI action, would this not impact the Close Complete UI action on every catalog task? This variable and it being mandatory is Closed Complete state is isolated to my one catalog item workflow and the task it is creating.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2016 02:44 PM
Well then you need to create a new Ui action with the same name and copy this script in there and put this in the Ui action conditions
current.request_item.cat_item=='sys_id of catalog item'
For the existing UI action, put this condition in there. So that it will only be visible for other catalog items
current.request_item.cat_item!='sys_id of catalog item'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2016 03:07 PM
Doing that right now, but instead of checking the cat_item on the catalog task, I am looking for the wf_activity sys_id, as this catalog task is going to be one of many within my catalog item workflow.
Added in the condition, but it doesn't seem to be quite working as I had planned. Do you know by chance if wf_activity == '<sys_id>' can be used in a UI action condition?