Catalog Item variable mandatory on only one task

Jason Stephens
Kilo Guru

I need to make a catalog item variable mandatory on only one task. I do not need it to be mandatory when submitted, I just need it to be mandatory on one of the tasks that get generated by the workflow.

Thanks for the help.

Jason

1 ACCEPTED SOLUTION

DrewW
Mega Sage
Mega Sage

have you tried

!g_form.getValue("variables.myvar").isNul()


View solution in original post

24 REPLIES 24

Community Alums
Not applicable

Hi Jason,

You can create catalog client script to hide this field when this is submitted and after it you can client script attached to a sc_task.


Jason Stephens
Kilo Guru

I'm not following you....

I don't care to hide the field - I just need it populated at a certain stage (task) of the workflow. At that point I need it to be mandatory and nowhere else. Once this task has been completed, I should be ok since the variable is now populated.


Take a look at this wiki article. You could use setMandatory() and base it off of some unique attribute of that task, possibly short description if that won't change.

http://wiki.service-now.com/index.php?title=Client_Script_Access_to_Variable_Fields_on_Task_Records


Jim Coyne
Kilo Patron

I'm getting close to the point of having to do the same thing you are and here's what I'm thinking.

Using Workflow Variables, you can show the variables on the appropriate tasks and they must be filled in before the task is closed. They can also be displayed on tasks further down the line if required.

But here's the problem with mandatory variables: you cannot save the record until all those fields contain some data. And it actually affects the RITM record as well, as it will display those workflow variables. What if the techs want to add notes or comments before they even know the answer to the variable? Or have only some of the required data? Can't be done. Well, not OOB at least.

I was thinking of adding some code to the "Save" and "Update" UI Actions that sets "g_form.checkMandatory = false" so that the mandatory field check is skipped before the record is saved. You can have logic to check to make sure the record is in a particular state (i.e. do not skip the check if the user is closing the task, etc...).

I'm going to play around with this to see how it goes. I don't like the idea of using the client scripts because you have to keep adding to the script as you add new variables. Maybe something could be done based on the name of the variable (prefix the names of all Workflow Variables with some string). But you still get into the situation of "we need this variable for this item, but not for that one". Can get pretty hairy real quick.