Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Issue in g_scratchpad(Using on submit client script)

Venky Kshatriy2
Tera Contributor

Hi Team,

 

below mentioned code i am used to call the script include to on submit client script and setting value based on that restrict the user
front of the service portal it's working fine i am getting value and it's set  to variable but
If i used the in catalog item we have a TRYIT UI action if use this button and test click the order button  i am getting the bellow error
onSubmit script error: ReferenceError: g_scratchpad is not defined:
function () { [native code] }
 
function onSubmit() {

    if (g_scratchpad.validForm) {
        return;
    }

    var reason1 = g_form.getValue('reason1');
    var reason2 = g_form.getValue('reason2');

    var mrvs = g_form.getValue('risk_rating_from_country');

    var vk = new GlideAjax("Decision_table_risk_rating");
    vk.addParam('sysparm_name', 'getriskratings');
    vk.addParam('sysparm_from', g_form.getValue('from'));
    vk.addParam('sysparam_to', g_form.getValue('to'));
    vk.addParam('sysparam_mrvs', mrvs);

    vk.getXML(function risk(response) {

        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert('risk rating' + answer);
        g_form.setValue('risk_rating', answer);
        if (answer == 1 && reason1 == '' && reason2 == '') {
            g_form.setVisible('reason1', true);
            g_form.setVisible('reason2', true);
            g_form.setMandatory('reason1', true);
            g_form.setMandatory('reason2', true);
            g_scratchpad.validForm = false;
        } else {
            g_scratchpad.validForm = true;
            g_form.submit();
        }
    });
   
    return false;


}
 
VenkyKshatriy2_0-1721803949456.png

Front of portal it's setting the variable value in below image

VenkyKshatriy2_3-1721804027756.png

 

 

could pls help to resolve this error

 

Advance thanks.


 

1 ACCEPTED SOLUTION

-O-
Kilo Patron

As far as I know g_scratchpad is not supported in CMS - only in Portal.

A workaround could be "simulating" it, something like:

function onSubmit () {
	var scratchpad = getExistingScratchpad() || getCustomScratchpad();

	if (scratchpad.validForm) {
		return;
	}

	var reason1 = g_form.getValue('reason1');
	var reason2 = g_form.getValue('reason2');

	var mrvs = g_form.getValue('risk_rating_from_country');

	var vk = new GlideAjax("Decision_table_risk_rating");

	vk.addParam('sysparm_name', 'getriskratings');
	vk.addParam('sysparm_from', g_form.getValue('from'));
	vk.addParam('sysparam_to', g_form.getValue('to'));
	vk.addParam('sysparam_mrvs', mrvs);

	vk.getXML(function risk (response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");

		alert('risk rating' + answer);

		g_form.setValue('risk_rating', answer);

		if (answer == 1 && reason1 == '' && reason2 == '') {
			g_form.setVisible('reason1', true);
			g_form.setVisible('reason2', true);
			g_form.setMandatory('reason1', true);
			g_form.setMandatory('reason2', true);
			scratchpad.validForm = false;
		}
		else {
			scratchpad.validForm = true;
			g_form.submit();
		}
	});

	return false;

	function getCustomScratchpad () {
		return NOW.g_scratchpad = NOW.g_scratchpad || {};
	}

	function getExistingScratchpad () {
		if (typeof g_scratchpad != 'undefined')
			return g_scratchpad;
	}
}

 

View solution in original post

11 REPLIES 11

Thanks for explain @-O-  it's really helpful to me

You're most welcome 🙂