The CreatorCon Call for Content is officially open! Get started here.

Make field mandatory before Task can be closed

booher04
Tera Guru

Hello,

I have a variable called "Workflow Progression" that is only on a certain task that fires(UAT Testing Task) from the workflow at a certain point.  The purpose of the field/variable is to ask what the workflow should do next:  Move to Production, Move to RollBack or Close the request(closed skipped).  This variable only appears on the UAT Task.  I need to figure out how to get the field to only be Mandatory when the "Close Task" ui action button is clicked.  We assign this task to different users so we need to open an update it without this field being mandatory all the time.

function onSubmit() {
if(g_form.getValue('state') == '3')
{

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

return false;

}

}

This is what I came up with.  Any help on this?  

15 REPLIES 15

So it looks like it might be working now, however it sets the task to "Close Complete" but it stays on the task, it doesn't actually "save and exit" the form.  Is there something I need to add in that will "close task" but also save and exit the form?

After the user selects the value in the field he will have to hit the close task button again or save the form manually.

 

-Pradeep Sharma

I hit the "Close Task" the 2nd time after filling in the mandatory field, however it doesn't move from the task.  It closes it(sets the state to "Closed Complete") but it does not go back to the RITM.  In order to get back to the RITM, I have to then hit  "Save and Close".

So I went a little different route as that client script wasn't redirecting properly and I tried to do it on the UI Action instead.  

Condition: 

current.state < 3 && current.approval != 'requested' && !g_form.getValue("variables.workflow_progression") == 'none'

Script:

function closeTask(){
var shortDescription = g_form.getValue('short_description');
if(g_form.getValue('state') == '3' && action == 'close_sc_task' && shortDescription.indexOf("UAT Testing Task") != -1);
g_form.setMandatory('workflow_progression', true);
g_form.setValue('state', 3);
gsftSubmit(null, g_form.getFormElement(), 'close_task');

}

if (typeof window == 'undefined')
updateTask();
function updateTask(){
current.state = 3;
current.update();

}

It's not stopping me from closing this task when the "workflow progression" variable is 'None'.  

You need to set the field mandatory and after the do a 

if(g_form.checkMandatory){
   //If true then the field is filled out and do nothing.
else
   return false;

I don't think there are any docs on the g_form.checkMandatory.

So your over all code should look something like this but I did not test.

function onSubmit() {
   var action = g_form.getActionName();
   var shortDescrition = g_form.getValue('short_description');
   if(g_form.getValue('state') == '3' && action == 'close_sc_task' && shortDescrition.indexOf("UAT Testing Task") != -1){
      g_form.setMandatory('variables.workflow_progression', true);
      if(!g_form.checkMandatory)
         return false;
   }
}

EDIT: You may want to put in a message about why they cannot submit the form.