Here is my solution that will make variables mandatory upon closure of a specific task:



1. Create a Business Rule to capture the Workflow Activity name:



Most likely you have a given task that the variables should be mandatory for. Because of that, we can leverage the name given in the workflow for the Create Task workflow activity that is found in a hidden reference field on the Catalog Task table. Here are the details for the Business Rule:


Name: Set g_scratchpad for sc_task


Table: Catalog Task [sc_task]


When: display


Script:


function onDisplay(current, g_scratchpad) {


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


}



2. Create a UI Policy that runs on the Catalog Task [sc_task] table:



We want this UI Policy to only run when the record is being closed to allow the user to fill out other fields and not be forced to fill in the variable until it is truly needed. For this example, I will be using a variable called s_task_var_01 and will be using it on a workflow activity called "Task One". Here are the details for the UI Policy:


Table: Catalog Task [sc_task]


Reverse if false: true


Order: 300


Global: true


Run scripts: true


Short Description: Make Variables Mandatory on Close


Conditions:


State | is | Closed Complete


Execute if True:


function onCondition() {


      if (g_scratchpad.wf_activity == 'Task One') {


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


      }


}



Execute if False:


function onCondition() {


      g_form.setMandatory('variables.s_task_var_01', false);


}



3. Change the Close Task UI Action:



My guess is that the OOB UI Action only closes the task and does not check to see if any fields or variables are mandatory. If that is the case, just disable the OOB UI Action called Close Task and create a new one. Here are the details for the UI Action:


Name: Close Task


Table: Catalog Task [sc_task]


Order: 100


Action name: close_task


Client: true


Onclick: closeTaskCheck();


Script:


function closeTaskCheck() {


      if (g_scratchpad.wf_activity == 'Task One') {


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


      }


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


}


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



function serverCloseTask() {


      current.state = 3;


      current.update();


}



Feel free to adjust to account for your variable name(s) and Workflow Activity Names accordingly. Let me know if you have any questions.