Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Is two-way synchronization between two catalog variables technically supported inside Service Portal

profile
Tera Contributor

Is two-way synchronization between two catalog variables technically supported inside Service Portal.

I have two catalog variables inside a variable set:

euid (text)

associate_name_common (reference to sys_user)

Both fields need to stay synchronized:

When the user enters an EUID, the script should populate associate_name_common.

When the user selects associate_name_common, the script should populate EUID. This is not works correctly in Maintain Item view and Service Portal (Try It)

Important details:

Both variables are on a variable set, used on 25 items

Using onChange Catalog Client Scripts

Using GlideAjax + Script Include

Even with flags like:

g_form.setParameter('sysparm_skip_euid_update')

window._lock

g_scratchpad

isLoading

→ the loop continues in Service Portal and Maintain Item view(platform ui) view.

I want solution to this problem. Please, anyone help me out from this problem

Below I am attaching my Catalog Client Scripts and Script Include.

I have tried by creating all the server side script include code in one script include itself it doesn't work 

And both script include code are Client callable.

 

var UserLookupAjax = Class.create();

UserLookupAjax.prototype = Object.extendsObject(AbstractAjaxProcessor,

getUserByEUID: function() {

var euid = this.getParameter('sysparm_euid');

if (!euid) {

return '';

}

var user = new GlideRecord('sys_user');

user.addQuery('u_euid', euid);

user.query();

if (user.next()) {

return user.sys_id;

}

return '';

},

type: 'UserLookupAjax'

});

 

 

 

var UserLookupEUID = Class.create();

UserLookupEUID.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getEUIDByUserSysId: function() {

var sysId = this.getParameter('sysparm_user_sysid');

if(!sysId) {

return '';

}

var user = new GlideRecord('sys_user');

if(user.get(sysId)) {

return user.u_euid.toString();

}

return '';

},

type: 'UserLookupEUID'

});

 

 

 

function onChange (control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {

return;

}

// Type appropriate comment here, and begin script below

var ga = new GlideAjax('UserLookupEUID');

ga.addParam('sysparm_name', 'getEUIDByUserSysId');

ga.addParam('sysparm_user_sysid', newValue);

ga.getXMLAnswer (function(response) {

if (response) {

g_form.setValue('euid', response);

} else {

g_form.setValue('euid', '');

}

});

}

 

 

function onChange (control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {

return;

}

var ga = new GlideAjax ('UserLookupAjax');

ga.addParam('sysparm_name', 'getUserByEUID');

ga.addParam('sysparm_euid', newValue);

ga.getXMLAnswer (function(response) {

if (response) {

g_form.setValue('associate_name_common', response);

} else {

g_form.setValue('associate_name_common', '');

}

});

}

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

One way to attempt this is in both client scripts, within the if (response) block or adding AND (&&) to this if statement, also do a getValue on the field that's about to be changed, and don't setValue if it = response. 

Mark Manders
Mega Patron

Why not only use the reference field? Since you can only search for people that are in the system (otherwise they can't be in sync). If you use the look up, you have the fields to search for the user. Then you can just use 'auto populate' to fill the string field.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark