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

@Y_O Thanks for the quick resposnse!