Show Field Message if a user is a VIP?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 07:59 AM
Hello,
I've been banging my head against a wall for quite a while now trying to figure out what I assumed would be a relatively simple thing.
I'm working on the sc_request form, and am trying to use a client script to make a field message show when a user is a VIP (VIP set to true on their sys_user record). I have tried g_scratchpad, getReference() and GlideAjax however I am having absolutely no luck, I know this is probably a really simple thing but don't suppose anyone knows the way to do it?
The closest I got was with g_scratchpad linking to a very simple display business rule
g_scratchpad.requestor=current.requested_for.vip;
however I couldn't seem to get an if/else statement to work with it when calling it in my client script. If anyone knows the best solution it would be greatly appreciated.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 08:03 AM
Hi @Jake McC
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 08:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 09:03 AM
@Jake McC Could you please share your business rule and client script code where you are facing issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 09:14 AM
HI @Jake McC ,
I trust you are doing great.
First, you need a business rule to set the value in g_scratchpad
. Your approach with g_scratchpad.requestor=current.requested_for.vip;
is correct. This business rule should be on the sc_request
table and set to run onDisplay
.
Display Business rule script :
(function executeRule(current, previous /*null when async*/) {
// Populate scratchpad with VIP status
g_scratchpad.requestorIsVIP = current.requested_for.vip;
})(current, previous);
Client script :
(function onLoad() {
// Use the scratchpad value to determine VIP status
if (g_scratchpad.requestorIsVIP) {
// Display your message here if the user is a VIP
var message = "Your custom message for VIP users.";
g_form.addInfoMessage(message);
}
})();
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi