Setting a Catalog Task variable to mandatory based on the value of another

Wayne Richmond
Tera Guru

Hi all. I've been reading some of the many discussions on Catalog Task variables in order to resolve my issue but haven't found anything definitive. Here's what I'm trying to achieve:

On a Catalog Task I have two variables 'sdr_replace_success' and 'sdr_issues'. sdr_replace_success is a Yes/No field with None. If the selection is 'no' I want to make sdr_issues mandatory. To do this I've been trying to use a UI Policy with Scripts enabled. Here is what I've ended up with with no success:


task1.png

task2.png

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

I think you are creating this as a "normal" UI Policy on the Task form, correct?   I would create it as a Catalog UI Policy instead and check the "Applies to Catalog Tasks" field:


____Jim_C_____.png



You may have to switch to the the "Advanced" view to see the field.   And then you can use a "Catalog UI Policy Action" to set the variable to mandatory instead of with a script.


View solution in original post

9 REPLIES 9

Perfect Jim, thank you. I hadn't realised those Advanced options were available!




Yeah, I wish they had not created all those "Advanced" views and hide some pretty basic options on them where a lot of people never see them.


Agree. If you're just setting it based on variables alone, this is the best solution. If you want to use the catalog task fields, this won't work as far as I know. In my case, I don't want these fields mandatory until the task is being closed but I don't see anything to allow that. I can do it on the sc_task ui policy instead using the scripts.


marcguy
ServiceNow Employee
ServiceNow Employee

This wiki article covers the topic:


http://wiki.servicenow.com/index.php?title=Client_Script_Access_to_Variable_Fields_on_Task_Records#g...


actually variables. should be there as explained on the wiki, there may be a field already called that variable name.


  • g_form.setMandatory(name, mandatory)

staceyrocheleau
Kilo Guru

Maybe because it's considered a related field. I've found in the past that UI policies don't work well with related field values in the conditions. Not sure if this has changed.



I found I had the same problem if I tried to put a variable as a condition. Instead, what worked for me is that I do some condition check within the script itself. For my stuff, I want to set some variables to mandatory if the task is being closed and another variable is set to a certain value.



My condition is:



State is Closed Complete AND
Request Item.Item is <My item containing the variable>



In the script I do a check. If it's being closed and the user selected "direct line", I want the direct line field to be mandatory.




function onCondition() {


  if (g_form.getValue('variables.phone_requirements') == 'Direct Line') {


  g_form.setMandatory('variables.phone_did',true);


  }


}