Make catalog task variables mandatory on "Close Complete"

SC10
Kilo Guru

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:

  1. (function executeRule(current, previous /*null when async*/) {  
  2.   if(current.variables.offboard_desktoprecoverassets == '' && current.state == "3"){  
  3.        
  4.   current.state=previous.state;  
  5.   current.setAbortAction(true);  
  6.   gs.addInfoMessage('NOTICE: Please select an option for desktop recovery below completing the task.');  
  7.   gs.setRedirect(current);  
  8.   }  
  9.  
  10.  
  11. })(current, previous);  
1 ACCEPTED SOLUTION

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;


  }


  }


}


View solution in original post

24 REPLIES 24

Why do you want to check for wf_actvity? Do you want this to be only applied for one catalog task of this workflow?


Yes, and I have just done that successfully! I got the catalog client script to do a check for the wf_activity and then modified the UI action script that you provided for the check for the wf_activity instead. Not checking for the catalog_item value.



You saved the day again


Did this solution still work for you after publishing a new version of your workflow? It appears the act of publishing creates a brand new wf_activity record. I thought this sounded like a good solution until I published a new version and the functionality that relied on that ID stopped working.


Jahnavi7
Mega Contributor

Hi,

 

How can you get that can to tell me.

Greg Farley
Tera Contributor

I created this today based off some of my own work and some of the structure from peoples suggestions, this is a client script not a catalog client script, found this to be better as I could use it across multiple RITMS and have done so by using an array of values for the RITMs it should be actioned on 

 

function onSubmit(){

	var ritm = g_form.getValue("cat_item");
	var cat_items = [Array of catalog items it should be active on here];
	var state = g_form.getValue("state");
	var variable1 = g_form.getValue(variables.variable1);
	var variable2 = g_form.getValue(variables.variable2); 
//variables will be specified by variables.variable_name

        //if the state is closed complete and the catalog item being submitted is included on my array of RITM sys_ids specified above
	if(state == 3 &&(cat_items.includes(ritm))){
//if varaibles are empty
		if(variable1 == "" && variable2 == ""){

//set variables to mandatory
		g_form.setMandatory("variables.variable1",true);
		g_form.setMandatory("variables.variable2",true);
//return false to prevent submission
		return false;
		}

	}
}