- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2019 02:27 PM
Hello all,
I am writing an onSubmit script which will not allow the user to close the task if a variable from the catalog item that I display on the catalog task (I display it by selecting it in the workflow using the slushbucket). I tried using g_form.getValue('variables.variable_name'). This seems to not work...
Any ideas why? I'll post the script below. Also the onsubmit script is also preventing saving/updating..
Script:
function onSubmit() {
if(g_form.getActionName('close_task') && g_form.getValue('short_description') == 'Precheck for Server Snapshot' && (g_form.getValue('variables.mc_storage')!='false' || g_form.getValue('variables.mc_storage')!='true')) {
var val = g_form.getValue('variables.mc_storage');
alert(val.getDisplayValue());
return false;
}
return true;
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2019 06:15 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
‎03-27-2019 06:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2019 06:10 PM
Yes Just like this!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2019 06:27 PM
Okay, if that is the case, we should be able to prevent submission using the business rule. Could you try this?
Advanced: checked
When: Before
On: Update
Script:
(function executeRule(current, previous /*null when async*/) {
// mc_storage is true or false right?
if(!current.variables.mc_storage){
gs.addErrorMessage("MC STORAGE needs to be true!");
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2019 06:31 PM
On SCTask I see they have the following inactive script:
function onLoad() {
var variable_map_items = $("variable_map").querySelectorAll("item");
for (var i=0; i < variable_map_items.length; i++) {
var variable = variable_map_items[i].getAttribute("qname");
g_form.setReadOnly("variables."+ variable, true);
}
}
Does this help at all?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2019 06:43 PM
That is how they set the variables to read only in the past but there is a new way of doing this now using g_form.setVariablesReadOnly(true);
You could try that script you posted to get the value of the variables but note that it is considered DOM manipulation and is not best practice. I would much rather use the business rule way instead