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

Juhi Poddar
Kilo Patron
Kilo Patron

Hello @GergelyP 

I tried your script in my PDI and it worked for me.

JuhiPoddar_0-1746533223574.png

  • I don't think there is an issue with the function name. 
  • The error is the warning message and so this should not block the data from script include.

Try this script to check if the response is received on client side:

function onLoad() {
    //Type appropriate comment here, and begin script below
    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) {
            g_form.addInfoMessage("Response: " + response);
            // Set the field value with the returned response
            //g_form.setValue('test_string_field', response);
        } else {
            g_form.addInfoMessage("Response not received");
            // Handle cases where no response is returned
            //g_form.setValue('test_string_field', 'No message returned');
        }
    });
}

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

 

Hello @Juhi Poddar ,
Thank you for reply.

I modified my script accordingly.

This is on the Platform:

GergelyP_0-1746534607934.png

This is on the Portal:

GergelyP_1-1746534671944.png

Same Script Include, same Catalog Client Script...

 

GlideFather
Tera Patron

Use Catalog Client Scripts for Portal (or Employee Center),
Use Client Scripts for backend behaviour

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


SumanthDosapati
Mega Sage
Mega Sage

Hey @GergelyP 

 

I guess a line missing at the end of the script include.

something like below will be present at the end of the script include.

    type: 'SimpleExampleScriptInclude'

 

Looks like that line got deleted in yours. and also a comma missing at the end of the function after }

Try creating a new script include and see the syntax.

 

Try and let me know if that helps.

Regards,

Sumanth