How do i call an onSubmit client script on a catalog task for only certain variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 11:02 AM
I have a catalog item where i am creating 2 catalog tasks in the workflow.
When i close the first catalog task in the workflow, it opens another catalog task.
There are about 6 or 7 check box variables that are only visible on the the first catalog task and these are mandatory. The mandatory check for the checkbox variables
is being called on the OnSubmit event. IT works great on the first task.
However these checkbox variables are not available on the 2nd task and don't need to be checked for mandatory. But since my script runs on the OnSubmit it is triggered
for all the catalog tasks.
How do i make this script run only on the first task. Is there a way to check if the check box variables exist on a task before calling the OnSubmit?
Any input is appreciated.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 11:29 AM
Based upon what you describe, I am guessing that you want to have specific variables become mandatory only on a particular task, and only when the record becomes closed. If this is true, we can use a UI Policy on the Catalog Task table (not a Catalog UI Policy) to achieve this. I have done this before, so if this is the case and you want more information, let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 11:42 AM
The checkbox variables need to be mandatory only on the first task. I mean ideally i would like the variables to mandatory on the first task all the time.
But i think as long as they are mandatory at the time of closing the task it should be fine.
Yes, i would like to know how to make them mandatory using a UI Policy on the catalog task table instead of a catalog ui policy.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 12:33 PM
My guess is that you want to check to see if at least one checkbox is checked when a specific Catalog Task is closed. If that is true, then you should be able to leverage the wf_activity field. Most likely you are using unique names in your workflow, you can then leverage those names in your script.
Since the wf_activity field on the Catalog Task record shows the name of the task you created in the workflow, we can leverage that.
For my example, I will have two Catalog Tasks in my workflow:
Configure Network
Install Software
1. Create a Business rule that captures the wf_activity name:
Name: Set g_scratchpad for sc_task
Table: Catalog Task [sc_task]
Advanced: true
When: Display
Script:
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.wf_activity = current.wf_activity.getDisplayValue();
})(current, previous);
2. Change your Client Script to leverage the g_scratchpad.wf_activity value:
For this example, I am just calling the value to show in an alert if the value is something specific. You can adjust this Client Script accordingly to include your checkbox checks.
Name: Alert if activity is Install Software
Type: onSubmit
Script:
function onSubmit() {
if(g_scratchpad.wf_activity == 'Install Software') {
Alert('This is a ' + g_scratchpad.wf_activity + ' task.');
}
}
Since these are checkboxes, I would not recommend making them mandatory since you then have to make all of the checkboxes checked. Hopefully this will give you enough to complete.
Let us know if you encounter any difficulty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 12:54 PM
Yes, you are correct. There are 6 check box values ( so 6 variables) and i want to check if atleast one of the 6 checkboxes is checked.
I do have about 18 checkbox variables that are being used on the task. A set of 6 checkbox variables makes up the values for 1 set.
So basically i have to do this check on all these 18 variables.
Let me try out the solution that you have suggested and i will let you know if it worked or not. Thanks for your help.