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

Did you create the onDisplay Business Rule? If you did, you should be able to determine what the Workflow Activity name is through the JavaScript Editor [Control][Shift][j]. Then run the following to get what the activity name is when you are in that task:



alert(s_scratchpad.wf_activity);



Let us know what the Workflow Activity is so we can adjust the code accordingly.


Tee1
Giga Contributor

Yes first ths I did was to create the display business rule.



The task in the workflow is called "Fulfill_AD_Task"


Based upon the thread as well as what you indicated, the Close Task UI Action should be the following:



function closeTaskCheck() {


      if (g_scratchpad.wf_activity == 'Fulfill_AD_Task') {


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


      }


      gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');


}


if (typeof window == 'undefined') serverCloseTask();



function serverCloseTask() {


      current.state = 3;


      current.update();


}



I am hoping that Fulfill_AD_Task is the actual name of the Workflow Activity. Is that what shows up when you view workflow from the Catalog Item? If it is, then it should work. If not, please give us a screen shot of your UI Action as well as your workflow highlighting which task this occurs with.


Tee1
Giga Contributor

Hi Christopher, the task is called Fulfull_AD_Task (screenshot below)



I have done as advised and changed the OOTB Close Task UI button and it no longer works at all...



find_real_file.png


Send me an email (chris.johnson AT fruitionpartners.com) and let me know your availability. I would like to see what you have built so far and make sure that it is set up properly.