- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 02:44 AM
Hello,
I have a requirement to show an alert if the record already exists in the table for the same name and show the link to the record through alert or infomessage. For this I wrote a Catalog client script and is working while doing 'Try it' but not working when I am trying the same through portal.
My OnChange Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var name = g_form.getValue('u_full_name');
var usr = new GlideRecord('u_eap');
usr.addQuery('u_full_name',name);
usr.query();
if(usr.next()){
var link = '<a href="u_eap.do?sys_id=' + usr.sys_id + '" class="breadcrumb" >' + usr.u_full_name + '</a>';
var message = 'The EAP record already exists for the name entered. Please check here' + link + ' .<br/>';
g_form.addInfoMessage(message);
}
}
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2020 08:40 AM
Hi Shwetha,
GlideRecord is not allowed in client script in portal; so it would break; Refer below
GlideRecord Client API does not work in the Service Catalog standard UI but works in Service Portal
You need to use GlideAjax + Script Include approach for this -> it would work in native and portal both
Updated code below for GlideAjax
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var name = g_form.getValue('u_full_name');
var ga = new GlideAjax('u_userInfoAjax');
ga.addParam('sysparm_name', "getInfo");
ga.addParam('sysparm_userFullName', name);
ga.getXMLAnswer(callBackMethod);
}
function callBackMethod(response){
var answer = response;
if(answer != ''){
var link = '<a href="u_eap.do?sys_id=' + answer + '" class="breadcrumb" >' + g_form.getValue('u_full_name') + '</a>';
var message = 'The EAP record already exists for the name entered. Please check here' + link + ' .<br/>';
g_form.addInfoMessage(message);
}
}
Script Include: Create Client Callable Script Include
var u_userInfoAjax = Class.create();
u_userInfoAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function(){
var name = this.getParameter('sysparm_userFullName');
var usr = new GlideRecord('u_eap');
usr.addQuery('u_full_name', name);
usr.query();
if(usr.next()){
return usr.sys_id;
}
return '';
},
type: 'u_userInfoAjax'
});
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 05:28 AM
Hello Alok,
This code is taking me to a new record rather than the existing record moreover I cannot see the info message populating in the portal too.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 06:04 AM
Could you please try with GlideAjax and Script Include. I see that you are using GlideRecord in client script and using of GlideRecord in client side scripting is not a good practice.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 03:12 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2020 04:39 AM
Hi, Please take a look at the above community link.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2020 08:40 AM
Hi Shwetha,
GlideRecord is not allowed in client script in portal; so it would break; Refer below
GlideRecord Client API does not work in the Service Catalog standard UI but works in Service Portal
You need to use GlideAjax + Script Include approach for this -> it would work in native and portal both
Updated code below for GlideAjax
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var name = g_form.getValue('u_full_name');
var ga = new GlideAjax('u_userInfoAjax');
ga.addParam('sysparm_name', "getInfo");
ga.addParam('sysparm_userFullName', name);
ga.getXMLAnswer(callBackMethod);
}
function callBackMethod(response){
var answer = response;
if(answer != ''){
var link = '<a href="u_eap.do?sys_id=' + answer + '" class="breadcrumb" >' + g_form.getValue('u_full_name') + '</a>';
var message = 'The EAP record already exists for the name entered. Please check here' + link + ' .<br/>';
g_form.addInfoMessage(message);
}
}
Script Include: Create Client Callable Script Include
var u_userInfoAjax = Class.create();
u_userInfoAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function(){
var name = this.getParameter('sysparm_userFullName');
var usr = new GlideRecord('u_eap');
usr.addQuery('u_full_name', name);
usr.query();
if(usr.next()){
return usr.sys_id;
}
return '';
},
type: 'u_userInfoAjax'
});
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader