Display a messgae on load if requested for is a VIP user (need to be bold and italic)

cheerla Nithin1
Kilo Explorer

Hi All,

please help me on the above question by using business rule

10 REPLIES 10

sachin_namjoshi
Kilo Patron
Kilo Patron

You need client script to achieve this requirement

 

function onChange(control, oldValue, newValue, isLoading) {
   //Get the 'caller_id' field and label elements
   var callerLabel = $('label.incident.caller_id');
   var callerField = $('sys_display.incident.caller_id');
   //Get the 'location' field
   var loc = g_form.getElement('location');
   
   //If the 'caller_id' field contains a valid reference
   if(newValue){
      //Get the caller object so we can access fields
      //Calls the 'popCallerInfo' function when the value is returned
      var caller = g_form.getReference('caller_id', popCallerInfo);
   }
   //If the 'caller_id' field does not contain a valid reference
   else{
      //Clear the value of the 'location' field
      if(loc){
         g_form.setValue('location', '');
      }
     
      //Remove any VIP styles present
      callerLabel.setStyle({backgroundImage: ""});
      callerField.setStyle({color: ""});
   }
   
   //Nested 'getReference' callback function for variable access
   function popCallerInfo(caller){
      //Location setting section
      if(loc && !isLoading && newValue != oldValue){
         g_form.setValue('location', caller.location);
      }
     
      //VIP formatting section
      if(caller.vip == 'true'){
         //Change the 'caller_id' label to red background with VIP icon
     var bgPosition = "95% 55%";
     if (document.documentElement.getAttribute('data-doctype') == 'true')
        bgPosition = "5% 45%";
                   
            callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition});
        //Change the 'caller_id' name field to red text
        callerField.setStyle({color: "red"});
     }
     else{
        //Not a VIP, remove temporary styles
        callerLabel.setStyle({backgroundImage: ""});
        callerField.setStyle({color: ""});
     }
   }
}

 

Anil Shewale
Mega Guru

Hi

if you use the Bussiness rule then write the following script:

following code work in my instance:

(function executeRule(current, previous /*null when async*/) {


if (current.caller_id.vip == true){

var message1 = 'CALLER is VIP:' ;

var message2 = message1.fontcolor("red");


gs.addInfoMessage(message2);
}

})(current, previous);

 

changing the font style refer the following thread:

https://community.servicenow.com/community?id=community_blog&sys_id=c05ee6addbd0dbc01dcaf3231f96196a

 

If it help mark helpful or correct 

Thanks and regards

Anil

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nithin,

2 approaches

1) client script:

Note: ensure you give valid field name for requested_for

function onLoad(){

var ref = g_form.getReference('requested_for', callBackMethod);

}

function callBackMethod(ref){

if(ref.vip == true){

var message = '<b><i>This is VIP User Message</i></b>';
g_form.addInfoMessage(message);

}

}

2) BR: Type is Display on that table

Note: ensure you give valid field name for requested_for

(function executeRule(current, previous /*null when async*/) {

	// Add your code here

if(current.requested_for.vip == true){
	var message = '<b><i>This is VIP User Message</i></b>';
	gs.addInfoMessage(message);
}

})(current, previous);

BR Output for incident Testing: Caller is VIP user

find_real_file.png

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar , Apologies to ping in much older thread. I did have practice req. to show an alert in Incident form if user is VIP to which I referred the above method using getReference and followed as below:

function onLoad() {
//Type appropriate comment here, and begin script below
var jcheck = g_form.getReference('caller_id', callBackMethod);

}

function callBackMethod(jcheck){

if(jcheck.vip == true){

alert('User is VIP');

}

}

 

Any thoughts?