- 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-15-2024 01:24 AM
- 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-17-2024 04:46 AM
Hi @SN_Learn ,
yes your solution did worked , I was using getXMLAnswer instead of getXML thats why it wasnt working.
Thanks