Show Field Message if a user is a VIP?

Jake McC
Tera Contributor

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!

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Jake McC 

https://www.servicenow.com/community/developer-forum/display-a-messgae-on-load-if-requested-for-is-a...

 

https://www.servicenow.com/community/itsm-forum/how-to-show-a-message-if-a-user-is-a-vip-in-agent-wo...

 

*************************************************************************************************************
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]

****************************************************************************************************************

shubhamdubey
Mega Sage

@Jake McC 

 

Please follow the below snapshot

 

Screenshot (50).pngScreenshot (49).png

Sandeep Rajput
Tera Patron
Tera Patron

@Jake McC Could you please share your business rule and client script code where you are facing issues.

Amit Gujarathi
Giga Sage
Giga Sage

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