The CreatorCon Call for Content is officially open! Get started here.

Catalog Client Script with GlideAjax call works on the Platform, but not on the Portal

GergelyP
Tera Contributor

Dear All,

 

I have this Script Include (Client callable):

var SimpleExampleScriptInclude = Class.create();
SimpleExampleScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	getMessage: function () {
		return 'Hello from the Script Include!'; // Simple response
	}
});

 

And I have this Catalog Client Script (UI Type is: 'All'):

function onLoad() {
    // Create a GlideAjax object and specify the Script Include
    var myGlideAjax = new GlideAjax('SimpleExampleScriptInclude');
    
    // Add the name of the method to call in the Script Include
    myGlideAjax.addParam('sysparm_name', 'getMessage');
    
    // Execute the GlideAjax call
    myGlideAjax.getXMLAnswer(function(response) {
        if (response) {
            // Set the field value with the returned response
            g_form.setValue('test_string_field', response);
        } else {
            // Handle cases where no response is returned
            g_form.setValue('test_string_field', 'No message returned');
        }
    });
}

It works on the Platform, because the value of the 'test_string_field' goes to 'Hello from the Script Include!' (the message from the Script Include).


However it does NOT work on the Portal, because the value of the 'test_string_field' goes to '

No message returned' (the message set in the Catalog Client Script).
 
Can anyone come up with an idea, how to make it work both on the Platform and on the Portal?
 
Thank you,
Regards
1 ACCEPTED SOLUTION

@GergelyP 

It's unable to call that script include from portal.

script include and client script both are in same scope or different ones?

Try with fresh client script and script include

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

13 REPLIES 13

I still suspect this error message is probably still because of function name cached in browser.

Change the function name to something else and try in different browser or incognito mode.

Hopefully that should work.

 

Regards,

Sumanth

GergelyP
Tera Contributor

With this:

var alertMessage = "Value: " + response + " Type: " + typeof(response);
alert(alertMessage);

Alert on Platform:
"Value: Hello from the Script Include! Type: string"

Alert on Portal:

"Value: null Type: object"

 

Can anyone help, please?

BR

@GergelyP 

It's unable to call that script include from portal.

script include and client script both are in same scope or different ones?

Try with fresh client script and script include

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Reus
Tera Expert

Can you check the UI type for the Catalog client script that you have created? It should be All.

GergelyP
Tera Contributor

Thank you for feedback, yes, it is 'All', still no luck. 😞