- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2024 06:48 AM - edited 07-14-2024 06:50 AM
Hello ,
I am trying to set VIP checkbox as true if a user is vip in incident form via client script and script include , here is my code but its not working . I created new field on incident form to set it but its not working and not returning anything via alert as well. Any help ?
Client Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 03:20 AM
Hi @NamitD ,
I have tried the below in PDI and it is working. Please check the below for reference:
Script Include(client callable - true)
var userV = Class.create();
userV.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isVip: function() {
var userID = this.getParameter('sysparm_value');
var userTab = new GlideRecord('sys_user');
if (userTab.get(userID)) {
var checkVIP = userTab.vip;
}
return checkVIP;
},
type: 'userV'
});
Also, check if there are any ACL created when you are creating script include, like below. You need to evaluate true according to it otherwise it wont work, OR you can disable the ACL after elevating to 'security_admin'.
onChange Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var c = g_form.getValue('caller_id');
var g = new GlideAjax('userV');
g.addParam('sysparm_name', 'isVip');
g.addParam('sysparm_value', c);
g.getXML(userVIPCheck);
function userVIPCheck(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_vip', answer);
}
}
Output:
Not a VIP User:
VIP User:
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2024 07:21 AM
Hi @NamitD ,
Please try the below, tested and working in PDI
Script Include:
var userV = Class.create();
userV.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isVip: function() {
var userID = this.getParameter('sysparm_value');
var userTab = new GlideRecord('sys_user');
if (userTab.get(userID)) {
var checkVIP = userTab.vip;
}
return checkVIP;
},
type: 'userV'
});
Onchange Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var c = g_form.getValue('caller_id');
var g = new GlideAjax('userV');
g.addParam('sysparm_name', 'isVip');
g.addParam('sysparm_value', c);
g.getXML(userVIPCheck);
function userVIPCheck(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_vip', answer);
}
}
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2024 09:55 AM
Hi @NamitD ,
I check your code there is one small error you write GlideRecord like
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2024 11:24 AM
Hi @NamitD ,
In Script include, in the line where GlideRecord is written, the table should be given in quotes.
The code is breaking there as the table name is not passed as a string.
Make this change and try. It will work.
Mark the response correct and helpful if the answer assisted your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2024 12:25 PM
Hi there @NamitD
Try replacing both these.
function call(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
alert(answer); // For debugging
g_form.setValue('u_vip', answer == 'true');
}
SI
isVip: function() {
var userId = this.getParameter('sysparm_value');
var userRecord = new GlideRecord('sys_user');
userRecord.addQuery('sys_id', userId);
userRecord.query();
if (userRecord.next()) {
return userRecord.vip == true ? 'true' : 'false';
}
return 'false';
},
If this helps kindly accept the response thanks much.
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India