- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 08:32 AM - edited 02-27-2025 08:34 AM
I have been struggling with this for a few months now. I set it aside for some time and now I am revisiting and hoping the community can help me get to a resolution.
For reference, I am starting with the solution in this thread. However, when I execute this function, I get a NULL response from the variable_map element and the script fails.
Below is my current UI Action settings and script, the HTML div, and the console error output I receive:
//Client-side 'onclick' function
function u_saveRecordClient() {
//ignore mandatory fields
var state = g_form.getValue('state');
console.log("UI Action details | State: " + 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) {
console.log("UI Action details | If statement 1 reached: TRUE");
g_form.checkMandatory = false; //ignore mandatory fields
try {
console.log("Trying to get allVariables");
//now ignore any mandatory variables
var allVariables = document.getElementById('variable_map').getElementsByTagName('item');
console.log("UI Action details | allVariables: " + allVariables);
for (var i = 0; i < allVariables.length; i++) {
var item = allVariables[i];
g_form.setMandatory('variables.' + item.getAttribute('qname').toString(), false);
}
} catch (err) {
console.log("Encountered error: " + 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();
}
<div id="variable_map" style="visibility:hidden;display:none">
<item qname="service_provider" id="57d6447a87120610d851c259dabb351e"></item>
<item qname="etf" id="b43ed07a87920610d851c259dabb35cd"></item>
<item qname="lte" id="235ed87a87920610d851c259dabb35eb"></item>
<item qname="device_details" id="3c9f85228716c210d851c259dabb3548"></item>
<item qname="cost_center" id="f1de54ba87920610d851c259dabb35bc"></item>
</div>
Encountered error: TypeError: Cannot read properties of null (reading 'getElementById')
@Steven Parker and @Jim Coyne have been very involved in this topic.
@Brad Bowman for visibility
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 09:39 AM
Hi @Evan McElfresh ,
try setting Isolate Script of UI action to false
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 09:44 AM
Bonus points for using Dark mode. Did you add the Isolate script field to your UI Action form or otherwise confirm that it is unchecked/false? Are you using this in the native UI or Service Portal / ESC / ...?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 09:48 AM
I just tried the Isolate Script method based on @Chaitanya ILCR 's recommendation. My reply above has the results.
At the moment I am attempting to save the sc_task in the Native UI. I will also need it to work in Service Operations Workspace, but I thought I would get it working in the native UI first.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 10:09 AM
I'll see if I can get Jim's solution to work, or a similar error in a current version PDI, but I don't think this will work in SOW. A use case I've solved for (in the native UI, but should also work elsewhere) is to not make variables mandatory until the task is attempted to be closed - so in the variable definitions or a UI Policy to override, the variables are not mandatory at the Catalog Task level, then where needed create an onSubmit Catalog Client Script that checks if the state value is 3/Closed Complete or whatever, then check if the short description is something in particular if you need to differentiate between Catalog Tasks. Use setMandatory to show the red asterisks, then for user-friendliness you can check if each variable is populated and show an alert or msg before returning false to stop the submit.
function onSubmit() {
if (g_form.getValue('state') == 3) { //Closed Complete
if (g_form.getValue('short_description') == 'Allocate IP Address) {
g_form.setMandatory('v_registration_date', true);
if (g_form.getValue('v_registration_date') == '') {
g_form.addErrorMessage('Registration date required');
return false;
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 10:31 AM
Jim's script worked fine for me in Xanadu. I just tried the Save one. Are these variables mandatory by definition, or with a UI Policy or Client Script on catalog tasks? If you populate the mandatory variables, does the form still Save OK not using this UI Action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 10:55 AM
They are only made mandatory by UI Policy. If the variables are populated, it saves just fine.