Save sc_task record with incomplete mandatory fields | getElementById failing

Evan McElfresh
Giga Guru

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:

EvanMcElfresh_0-1740674049664.png

 

 

//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();
}

 

 

EvanMcElfresh_0-1740673762832.png

 

 

 

<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 

Please mark this response as correct and/or helpful if it assisted you with your question.
1 ACCEPTED SOLUTION

Chaitanya ILCR
Mega Patron

Hi @Evan McElfresh ,

try setting Isolate Script of UI action to false

ChaitanyaILCR_0-1740677960500.png

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

11 REPLIES 11

I just discovered I hadn't deleted a previous Catalog Client Script in an attempt to fix this and that was what was throwing the new error after setting the Isolate Script attribute on my UI Action, so I am marking this one solved. Thank you for your quick responses!

Please mark this response as correct and/or helpful if it assisted you with your question.

I can confirm that the UI Action method does not work in SOW for now. I was hoping to keep the scripting generic, like the UI Action does, but I'll have to dig into the specific Catalog Items since the team here uses SOW almost exclusively.

 

Thanks again for all the discussion and help!

Please mark this response as correct and/or helpful if it assisted you with your question.