Why is g_scratchpad used in onSubmit Catalogue Client Script?

matthew_hughes
Kilo Sage

I've just been looking at the onSubmit below Catalogue client Script:

 
function onSubmit() {

    // If we already validated, continue
    if (g_scratchpad.isFormValid) {
        g_scratchpad.isFormValid = false;
        return true;
    }

    // // get the system property value that holds the names of all the checkboxes
    var gaProperty = new GlideAjax('sn_apm_di.LBGDigitalInterfacesURLUtils');
    gaProperty.addParam('sysparm_name', 'getSystemProperty');
    gaProperty.addParam('sysparm_propertyName', 'sn_apm_manage_bus_app_fields_catalog_item_checkbox_names');
    gaProperty.getXML(processCheckboxes);
    return false;

}

function processCheckboxes(response) {
    // get the string of checkbox names
    var answer = response.responseXML.documentElement.getAttribute("answer");
   
    // convert to an array
    var aryCheckboxes = answer.split(",");
   
    // det the default status that none have been selected
    blnSelectionMade = false;

    // loop through all the checkboxes
    for(var loop = 0; loop < aryCheckboxes.length; loop++){
        // if we find one that is selected
        if(g_form.getBooleanValue(aryCheckboxes[loop])){
            //update our variable
            blnSelectionMade = true;
            // break out from the loop
            break;
        }
    }

    //If a checkbox is selected, then allow the request to be submitted. Otherwise show the below error message
    if(blnSelectionMade){
        g_scratchpad.isFormValid = true;
        g_form.submit("submit");        
    } else {
        g_form.addErrorMessage('It looks like you have not changed any data. Please select a data point to update it.');
    }
}
 
However, what I've noticed in the catalogue item itself is that 'g_scratchpad' is not declared as a variable.
 
So I just wondering if anyone knows why 'g_scratchpad' is used in this catalogue client script and where the value comes from?
9 REPLIES 9

Dhanraj B
Tera Guru

Basically, g_scratchpad will be declared in display business rules to pass the information from Server side to client side. It will not be declared in the client script. You can look at the business rules of the table where the form is being viewed. 

 

-Dhanraj.

Ankur Bawiskar
Tera Patron

@matthew_hughes 

in this case it's basically used to handle synchronous GlideAjax

Reason being Synchronous GlideAjax is not allowed in portal and in scoped app

Async Validation in onSubmit Catalog Client Script in Service Portal and Synchronous Validation in N... 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@matthew_hughes 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar So does that explain why it is used in my script?  Does g_scratchpad hold a value? it's confusing because this is on a catalogue item on client side.