Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Setting Variable to Mandatory on/before Task Closure

Tee1
Giga Contributor

Hi All,

Hopefully someone can help with the following. it sounds simple enough, but I can't get what I want to do to work.

What I need to happen is for a variable on a request task form to become mandatory on or before the 'Close Task' action. I have explored this via UI Policy and got it to work for it to be mandatory. However, the issue I have with that method is the task will need some work completing before variable information is acquired and you cannot save it as the field has already become mandatory.

The method I am now exploring is the onSubmit client script, but I am open to other options...

function onSubmit() {

    var action = g_form.getActionName();

    if (action != 'close_sc_task')

          return;

    var state = '3'; // Closed Complete State

    if (action == 'close_sc_task');

    g_form.setMandatory('business_email', true); // business email is the variable that need to become mandatory

}

What I have seen with the above script is that the business email variable flashes briefly with the mandatory asterisk, but the task closes anyway. Any help would be appreciated.  

Many Thanks...

1 ACCEPTED SOLUTION

I think I used the wrong syntax for the business rule. After Helsinki, they changed the syntax and no longer use onBefore() onAfter() methods. See if you can use this in your Set g_scratchpad for sc_task business rule:


(function executeRule(current, previous /*null when async*/) {


      g_scratchpad.wf_activity = current.wf_activity.getDisplayValue();


})(current, previous);


View solution in original post

28 REPLIES 28

I'm afraid not, I can't seem to get anything from all the help that been given on my post to work.


can you share your entire on submit script. And to confirm once you are going to achieve this on task page right. It worked in my page .


Hey Vasmi.  I tried your script and it worked with one exception.  If I click close task and there is an existing field that is required and prompts me for input then once I input that field and click close task again - it bypasses the script and let's it go through.  Any ideas?

Surendra8
Kilo Contributor

This thread is Awesome....Thanks for the post..Helped me alot...