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

shubhamdubey
Mega Sage

@Jake McC 

 

Please follow the below snapshot

 

Screenshot (50).pngScreenshot (49).png

Sandeep Rajput
Tera Patron

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

Amit Gujarathi
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);
  }
})();