- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2012 10:12 PM
We have a few mandatory workflow variables setup. The variables are mandatory to ensure the techs populate them before closing a task as the information is required in subsequent tasks. Unfortunately, we have been running into problems with the Catalog Task form.
The problem with mandatory variables is you cannot enter information in some of the fields and/or variables and save the record - the blank mandatory variables prevent the update of the record. This is a valid use case as you do not always get all the required information at the same time and it would be nice to update the task as you receive that information. Same thing if a tech wanted to enter some info in the work notes or comments field - cannot save unless the mandatory fields are filled in.
This has been bugging me for a while but I think I've come up with a pretty good solution. I've created 2 new UI Actions on the Catalog Task form to override the global OOB Save and Update actions. Here is how the Save version is configured:
Name: Save
Table: Catalog Task [sc_task]
Action name: sysverb_update_and_stay (to override the OOB "Save" UI Action)
Client: checked
Form button: checked
Onclick: u_saveRecordClient()
Condition: current.canWrite()
Script:
//Client-side 'onclick' function
function u_saveRecordClient(){
//ignore mandatory fields
var state = g_form.getValue('state');
//we can save without filling in all mandatory fields and variables if the task is not closed or closing
if (g_form.getValue('state') != 3){
g_form.checkMandatory = false; //ignore mandatory fields
try {
//now ignore any mandatory variables
var allVariables = document.getElementById('variable_map').getElementsByTagName('item');
for(var i = 0; i < allVariables.length; i++){
var item = allVariables[i];
g_form.setMandatory('variables.' + item.getAttribute('qname').toString(),false);
}
} catch(err) {}
}
//Call the UI Action and skip the 'onclick' function
//this will execute the code below
gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs on the server, without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
u_saveRecordServer();
function u_saveRecordServer() {
action.setRedirectURL(current); //come back to the same record
current.update();
}
The Update version would be slightly different:
Name: Update
Table: Catalog Task [sc_task]
Action name: sysverb_update (to override the OOB "Update" UI Action)
Client: checked
Form button: checked
Onclick: u_updateRecordClient()
Condition: current.canWrite()
Script:
//Client-side 'onclick' function
function u_updateRecordClient(){
//ignore mandatory fields
var state = g_form.getValue('state');
//we can update without filling in all mandatory fields and variables if the task is not closed or closing
if (g_form.getValue('state') != 3){
g_form.checkMandatory = false; //ignore mandatory fields
try {
//now ignore any mandatory variables
var allVariables = document.getElementById('variable_map').getElementsByTagName('item');
for(var i = 0; i < allVariables.length; i++){
var item = allVariables<i>;
g_form.setMandatory('variables.' + item.getAttribute('qname').toString(),false);
}
} catch(err) {}
}
//Call the UI Action and skip the 'onclick' function
//this will execute the code below
gsftSubmit(null, g_form.getFormElement(), 'sysverb_update'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs on the server, without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
u_updateRecordServer();
function u_updateRecordServer() {
current.update();
}
The script sets "g_form.checkMandatory = false" in order to bypass the mandatory fields, but, unfortunately, it does not work with variables. So, I figured why not run through all the variables and remove their mandatory properties?
I'd like to get a few comments to see what people think. It seems to work fine so far. Now the real solution of course would be to have the "g_form.checkMandatory" property take variables into account as well. 🙂
To use them elsewhere, just change the Table field.
UPDATES:
- modified the code above to add a "try {} catch(err) {}" block to avoid problems when there are no variables on the form (thanks shill)
- added a missing "{" at the end of line 7 (thanks chucksimonds)
- added the separate settings for the Update UI Action
Solved! Go to Solution.
- 27,717 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2014 01:09 PM
Just setting this answer as correct as the actual thread was not meant as a question and it cannot be changed because it came from the original Community site.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2016 07:09 AM
Jim, this is brilliant, thank you.
One thing I noticed in your code is on line #13 of the first code block you pasted. You're using angle brackets <i> instead of square brackets [i]. No biggie as it was easy to figure out and fix.
I posted a question here: Save form logic (update or insert)
because I'd like to logically determine how the Save button works. Basically, if it's a new record, Insert and Stay. Otherwise, Update and Stay.
If you follow my link, I've explained in detail and provided code.
Any light you could shed would be great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2016 08:40 AM
Must have been a copy/pate issue, because that would never have worked. Thanks for letting me know.
I've responded to your question in the other thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2016 08:20 AM
jim.coyne - this is great! I've got the script working with some minor additions for our business use.
Was wondering if you had any ideas on the below
- I used your Update script (copied below) and it doesn't appear to work as a List Bottom Button - it doesn't seem to run at all
- I've got some bits in the script to set field values but one isnot working
- The current.caller_id doesn't set to the administrator that it looks up
function u_updateRecordClient(){
//ignore mandatory fields
var state = g_form.getValue('state');
//we can update without filling in all mandatory fields and variables if the task is not closed or closing
if (g_form.getValue('state') != 3){
g_form.checkMandatory = false; //ignore mandatory fields
}
//Call the UI Action and skip the 'onclick' function
//this will execute the code below
gsftSubmit(null, g_form.getFormElement(), 'close_reject_incident'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs on the server, without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
u_updateRecordServer();
function u_updateRecordServer() {
current.incident_state = 400;
var gr = new GlideRecord('sys_user');
gr.get('name','Administrator');
if (current.caller_id =='') {
current.caller_id.setValue(gr.sys_id);
}
if (current.assigned_to =='') {
current.assigned_to = gs.getUserID();
}
current.close_notes = "Incident Closed - Rejected. This is either a duplicate record or is otherwise an incorrectly logged Incident (e.g. by auto-forward from Service Desk mailbox).";
if (current.u_product =='') {
current.u_product = 'zz_other';
}
if (current.u_service_affected =='') {
current.u_service_affected = '0fb8a9905193c6003d3db4fa21e19000'; // this sets it to zz_other - use sys ID as it is a lookup field
}
current.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2018 09:25 PM
This is old...but gold! Thanks so much for sharing this solution!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2018 12:24 PM
You are welcome Amy!