g_scratchpad is not working giving error

gautam_dhamija
Tera Contributor

onSubmit script error: ReferenceError: g_scratchpad is not defined:
function () { [native code] }

code1:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    // Get field values
    var invoiceNumber = g_form.getValue('invoice_no');
    var invoiceDate = g_form.getValue('invoice_date');
    var invoiceAmount = g_form.getValue('invoice_amount');
    var vendorCode = g_form.getValue('vendor_code');

    // Alert concatenated values
    // alert('Invoice Number: ' + invoiceNumber + ', Vendor Code: ' + vendorCode + ', Invoice Date: ' + invoiceDate);
    alert(invoiceNumber);

    // Create GlideAjax object
    var ga = new GlideAjax('x_perii_account_0.CheckForDuplicity');
    ga.addParam('sysparm_name', 'checkForDuplication1');
    ga.addParam('sysparm_invoiceNo', invoiceNumber);
    ga.addParam('sysparm_invoiceAmount', invoiceAmount); // Fixed parameter name
    ga.addParam('sysparm_invoiceDate', invoiceDate); // Fixed parameter name
    ga.addParam('sysparm_vendorCode', vendorCode); // Fixed parameter name
    // alert('test');
    // Send request and handle response
    ga.getXMLAnswer(duplicate);

    function duplicate(response) {
        // response = response.trim();
        alert(response);
        if (response === 'true') {
            alert('responsetrue');
            g_scratchpad.duplicateRecord1 = 'false';  
        } else {
            alert('responsefalse');
            g_scratchpad.duplicateRecord1 = 'true';

        }
    }
}
Code2:
function onSubmit() {
   //Type appropriate comment here, and begin script below
   if (g_scratchpad.duplicateRecord1 == 'true') {
        alert('Duplicate invoice found. Please check the invoice number,amount and date');
        return false;
    }
   
}
Both are in scoped Application Code 1 is onchange client script and code 2 is on submit
5 REPLIES 5

Ranjane_Omkar
Kilo Sage

Hello @gautam_dhamija

 

As per my understanding you are aborting the submit action if duplicate record is found. If that the case why not use Before Insert BR and check the same thing which you have checking in script include.

---

If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.