- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2017 10:47 PM
Hi All, I am trying to learn using g_scratchpad variable in business rules and have made a simple program that is not working, so request some guidance.
1. I have a table called check-in and it has a reference field called guest.
2. I have a table called Guest and that has a field called VIP
3. I want a message to be shown using g_scratchpad when someone tries to checkin a VIP guest.
4. I created a display business rule on checkin table (Get VIP Flag) with the following script:
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.vip='current.x_53167_hotel1_guest.vip';
})(current, previous);
5. Then I have the following client script (Alert for VIP)
function onChange(control, oldValue, newValue, isLoading,
isTemplate) {
var showVIP = function() {
g_form.showFieldMsg('x_53167_hotel1_check_in.guest','Guest is a VIP');
};
if (isLoading) {
if(g_scratchpad.vip'){
showVIP();
}
return;
}else{
g_form.hideFieldMsg('x_53167_hotel1_check_in.guest');
}
if(newValue==''){
return;
}
}
6. The logs dont seem to have any error captured
22:42:32.622: App:Hotel1 ==> 'Get VIP flag' on x_53167_hotel1_check_in:CHE0001128
22:42:32.623: >> Entering scope [x_53167_hotel1]
22:42:32.623: << Exited scope [x_53167_hotel1], popped back into [rhino.global]
22:42:32.623: App:Hotel1
<== 'Get VIP flag' on x_53167_hotel1_check_in:CHE0001128
22:42:32.623: Finished executing before_display before business rules on x_53167_hotel1_check_in:CHE0001128
Please help. Thanks a lot.
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2017 09:45 AM
Hi Vivek,
I think you need to do GlideAjax, as per my understanding Business Rule get trigger when form loads or you save the record. When you will do onChange then at time there is no action happening on form. I tried below code and it works fine, please check if this helps.
onChange Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sys_id = newValue;
var userDetails = new GlideAjax("DisplayUserDetails");
userDetails.addParam("sysparm_name", "getUserDetails");
userDetails.addParam("sysparm_sys_id", sys_id);
userDetails.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
if(answer == 'true')
g_form.showFieldMsg('caller_id', 'User is a VIP');
else
g_form.showFieldMsg('caller_id', 'User is NOT VIP');
}
}
Script Include:
var DisplayUserDetails = Class.create();
DisplayUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails : function() {
var sysid = this.getParameter('sysparm_sys_id');
var newUserRecord = new GlideRecord('sys_user');
newUserRecord.addQuery('sys_id', sysid);
newUserRecord.query();
if(newUserRecord.next())
{
var guestIsVIP = (newUserRecord.vip) ? true : false;
return guestIsVIP;
}
},
type: 'DisplayUserDetails'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2017 03:23 AM
Hi Vivek,
Remove the single quotes from :
g_scratchpad.vip='current.x_53167_hotel1_guest.vip';
and try this:
g_scratchpad.vip=current.x_53167_hotel1_guest.vip;
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2017 08:38 AM
Thanks. I noticed and tried this already but still it didn't work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2017 09:45 AM
Hi Vivek,
I think you need to do GlideAjax, as per my understanding Business Rule get trigger when form loads or you save the record. When you will do onChange then at time there is no action happening on form. I tried below code and it works fine, please check if this helps.
onChange Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sys_id = newValue;
var userDetails = new GlideAjax("DisplayUserDetails");
userDetails.addParam("sysparm_name", "getUserDetails");
userDetails.addParam("sysparm_sys_id", sys_id);
userDetails.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
if(answer == 'true')
g_form.showFieldMsg('caller_id', 'User is a VIP');
else
g_form.showFieldMsg('caller_id', 'User is NOT VIP');
}
}
Script Include:
var DisplayUserDetails = Class.create();
DisplayUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails : function() {
var sysid = this.getParameter('sysparm_sys_id');
var newUserRecord = new GlideRecord('sys_user');
newUserRecord.addQuery('sys_id', sysid);
newUserRecord.query();
if(newUserRecord.next())
{
var guestIsVIP = (newUserRecord.vip) ? true : false;
return guestIsVIP;
}
},
type: 'DisplayUserDetails'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2017 11:06 PM
Hi Shishir
When I try to use Glide Ajax I get the following error while loading Checkin form:
AbstractAjaxProcessor undefined, maybe missing global qualifier
Any idea what might be wrong ?
Thanks
Vivek

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2017 11:11 PM
You must name the script include with the same name you define the class, in this case DisplayUserDetails, Can you please share the screenshot of your script include.