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 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);


Tee1
Giga Contributor

Hi Christoper,



Thought i'd give it one last shot with your amended code and hey presto, it worked!!! You are a gent, thank you for all your help.



I have another "hopefully" quick question...



I need for this to work for other Service Requests too, I have tested below and it works as I need it to. Can you see any pitfalls in the changes i've made?



UI Policy


find_real_file.png




Kindest Regards,




Mohammed



p.s.



I did make any changes to the Close Task UI action as you suggested, it worked with the OOTB Close Task UI action


So long as you have the Workflow Activity named the same and use the same variables you should be successful. If there are differences, you can always use multiple if conditions.


Harshit
Tera Contributor

Hi,



Instead of going for a UI Policy & Client scripts, you can try to check for the same variable in the workflow.


Eg - "X" variable has to be filled in before closing the task, so once the user closes the task - have an if condition/run script activity after the task to check if the "X" variable is filled in or not. (you can print the message also here.)


If no, use "rollback to" activity to open the task again.



Hope this helps!



Regards,


Harshit


Tee1
Giga Contributor

Hi Harshit,



I'd prefer to do this in the manner that Christopher suggested, but this sounds quite an interesting method to tackle my issues too.



Do you have and example of what the script would look like to achieve what I need?



Kindest Regards,