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

Difference between client scripts & catalog client scripts re: calling script includes?

C_dric Chen
Tera Contributor

So, I plagiarised the script include + client script to retrieve a user's e-mail address and populating a field (string, single-line text) with the retrieved e-mail address. They worked in the form view, but they didn't work in the record producer.

Since I merely copied and pasted the codes from the client script to the catalogue client script, something must have changed somewhere to make the catalogue client script not work. Would anyone happen to have any clues?

Thank you in advance!

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Ideally, it should work. Please make sure to update the script to include the Record producer variable name and include a few alert messages to see which script line is exactly not working.

 

- Pradeep Sharma

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi  Cédric,

Works OK for me. I'm using the same Script Include in both Catalog Item and Record Producer.

Script Include

var UserUtil = Class.create();
UserUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	getUserEmail: function () {
		var userSysId = this.getParameter('sysparm_user_sys_id');
		var grUser = new GlideRecord('sys_user');
		if (grUser.get(userSysId)) {
			return grUser.getValue('email');
		}
	},
    type: 'UserUtil'
});

1. Catalog Item

Client Script

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    var ajax = new GlideAjax('UserUtil');
    ajax.addParam('sysparm_name', 'getUserEmail');
    ajax.addParam('sysparm_user_sys_id', newValue);
    ajax.getXMLAnswer(function(answer) {
        if (answer.length > 0) {
            g_form.setValue('email', answer);
        }
    });
}

find_real_file.png

 Execution result

find_real_file.png

2. Record producer

Client script content is the same as catalog item

find_real_file.png

Execution result

find_real_file.png

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi again,

As I've replied in the other thread, is they all in the same scope?

https://community.servicenow.com/community?id=community_question&sys_id=9b53c9951baf8d90b4b577bc1d4b...

If they are in different scopes, Script Include should have "Accessible from" set to "All application scopes" and client script should specify script include using prefix "global."

e.g.

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