- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 08:41 AM
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...
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 01:09 PM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 09:05 AM
You indicate you have the variables made mandatory through a UI Policy. Is that a Catalog UI Policy, or a UI Policy that runs on the Catalog Task table? If it is the latter, then you should be able to put conditions on the UI Policy to only make the variables mandatory upon close.
I have done something similar whereby the variables will only be mandatory on close for certain tasks and not mandatory for others. Let me know if this is an approach you want to use and I can put together an example for you to model your solution off of.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 09:33 AM
Hi Christopher,
I am currently trying to get this to work only via a onSubmit Catalog Client Script, I deactivated the Catalog UI Policy. If you managed to get this to work this by a script in the Catalog UI Policy, i'm open to suggestions and happy to give this a go...
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 09:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 03:22 AM
Thank you very much for your detailed reply Christopher unfortunately it didn't seem to work for me.
it all made logical sense, not quite sure where is falls over.