How to Create a client script check if user is VIP or not, use script include to get answer true or false based on VIP flag and use script include answer in client script and validate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2022 02:20 AM
How to Create a client script check if user is VIP or not, use script include to get answer true or false based on VIP flag and use script include answer in client script and validate.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2022 04:14 AM
Hi,
Use below client script and script include.
Client script: create onchange client script on your table select the user field on form.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//if you comment below 3 lines it will works for onload
if (isLoading || newValue === '') {
return;
}
var gauser = new GlideAjax('global.getvipinfo'); //script include name
gauser.addParam('sysparm_name', 'getInfo'); // script include function that you defined
gauser.addParam('sysparm_user', newValue); // passing parameter to server
gauser.getXML(setDetails);
function setDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer"); //response will gets on answer variable.
if (answer == "true") {
g_form.addInfoMessage("Caller is a VIP User");
} else if (answer == "false") {
g_form.addInfoMessage("Caller is not a VIP User");
}
}
}
Script Include:
var getvipinfo = Class.create();
getvipinfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function() {
var user = this.getParameter('sysparm_user'); // sysid of user record
var usr = new GlideRecord('sys_user'); //query the user table
usr.addQuery('sys_id', user); //filter the record with sysid
usr.addEncodedQuery('vip=true'); //to check user VIP or not
usr.query();
if (usr.next()) {
return "true";
} else {
return "false";
}
},
type: 'getvipinfo'
});
Hope it helps!!
Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 04:07 AM
Hello, i try your script but in my PDI is always run and give caller is not a vip can you help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 02:25 AM
Hi,
Please close the thread by Mark it ✅ Correct/helpful, if this solves your issue.
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar