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

How to Call Script Include from Catalog Client Script

Y_O
Mega Expert

Hi Community,

I'm trying to call a script include from a catalog client script, but it doesn't work.

Some trials to investigate the cause and the results:

1. I changed the contents of the scripts to something very simple to investigate the cause, but the result is not returned.

2. I'm trying to spit out logs in the script include, but I don't see any logs. (Other script includes display the log, so you don't need to troubleshoot that part.)

3. The catalog client script itself is working fine, and "g_form.addInfoMessage" shows that null is returned from the script include.

Can anyone tell me what's wrong or detailed troubleshooting steps?

 

The following are the set values:

<Catalog Client Scripts>

    Applies to: A Catalog Item

    Active: True

    UI Type: Mobile / Service Portal (The result is the same even if it is All)

    Application: Global

    Type: onChange

    Applies on a Catalog Item view: True

<Script Include>

    Name: getCurrentOperationSchedule

    Application: Global

    Accessible from: All application scopes

    Client callable: True

    Active: True

    Protection policy: None

 

Below is the content of the scripts:

<Catalog Client Scripts>

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	
    // var selectedWork = g_form.getValue('regular_work'); //commented out for investigation

    var ajax = new GlideAjax('getCurrentOperationSchedule');
    ajax.addParam('sysparm_name', 'showSchedule');
    // ajax.addParam('sysparm_work', selectedWork); //commented out for investigation
	
    ajax.getXML(displaySchedule);
	
    function displaySchedule(response) {
        var currentSchedule = response.responseXML.documentElement.getAttribute("answer");

        g_form.addInfoMessage('The value is'+ currentSchedule); //returned message: The value is null
    }
}

<Script Include>

var getCurrentOperationSchedule = Class.create();
getCurrentOperationSchedule.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    showSchedule: function() {
        gs.info('Script Include getCurrentOperationSchedule Started');
	// var selectedWork = this.getParameter('sysparm_work'); //commented out for investigation

	return 'test';
    },

    type: 'getCurrentOperationSchedule'
});

 

I'm new to ServiceNow and JavaScript, so I expect easy-to-understand comments.

Thanks in advance,

1 ACCEPTED SOLUTION

As you're on San Diego, client callable ACLs are created. Are you testing your script include as an admin or by impersonating a user?

Has the necessary ACL been created with a name of getCurrentOperationSchedule?

View solution in original post

25 REPLIES 25

Mohith Devatte
Tera Sage
Tera Sage

Hello @Y.O ,

in the client script try to put the API name of the script include instead of calling it via name

Go to your script include and you will find the API name field ,copy it and paste it in glide ajax and give it a try .

var ajax = new GlideAjax('your_Script_include_api_name');

PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU

Hello @Mohith Devatte ,

Thanks for quick reply.

I tried changing the settings to the following but unfortunately the result was the same.

var ajax = new GlideAjax('global.getCurrentOperationSchedule');

 

@Y.O did you give the on change variable in the variable field in the on change client script ?

@Mohith Devatte Which part are you specifically asking? Please check the attached screenshot for the setting values.
I changed the target field in the catalog item form for testing. As a result, the client script is working properly.