- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 12:31 PM
Hello Im looking for a way to have a vairable field be Mandatory if the Task is set to closed complete.
Basically not allow users to close the SCTASK without filling out the variable. something like this.
Any help is appreciated. Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 12:47 PM
I have this requirement often. An onSubmit Catalog Client Script that Applies on Catalog Tasks is the way to go. You only need one script per catalog item. You can, and probably will have many iterations of this requirement - this variable is mandatory on this task and that one, and this one is mandatory if the task is closed complete, incomplete, or skipped,... - all just modifications to the if statements below
function onSubmit() {
if(g_form.getValue('state') == 3){//Closed Complete
if(g_form.getValue('short_description') == 'Request a Knowledge Article'){//to make this variable mandatory when only this task closes
g_form.setMandatory('v_testing_field', true);
if(g_form.getValue('v_testing_field') == ''){
alert('Testing field is required');
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 12:43 PM
You can do it with UI Policies or also OnChange client script (on state field) on sc_task table and make the variable mandatory.
OnChange Client script:
onchange: State
script:
g_form.setMandatory('current.variables.variable_name', true);
Thanks,
Rocky.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 12:44 PM
Hello,
You may try to create an UI Policy at Task level.
And an advanced script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 12:46 PM
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
‎02-23-2021 12:47 PM
I have this requirement often. An onSubmit Catalog Client Script that Applies on Catalog Tasks is the way to go. You only need one script per catalog item. You can, and probably will have many iterations of this requirement - this variable is mandatory on this task and that one, and this one is mandatory if the task is closed complete, incomplete, or skipped,... - all just modifications to the if statements below
function onSubmit() {
if(g_form.getValue('state') == 3){//Closed Complete
if(g_form.getValue('short_description') == 'Request a Knowledge Article'){//to make this variable mandatory when only this task closes
g_form.setMandatory('v_testing_field', true);
if(g_form.getValue('v_testing_field') == ''){
alert('Testing field is required');
return false;
}
}
}