Script for VIP user

sifynm
Tera Expert

                  As checked here Useful Task Scripts - ServiceNow Wiki, we have the following code which could be included in client scripts for VIP users. I have tried it on my instance and it is not working as specified in the document.

Change Urgency to High if User is VIP

name = Change Urgency to High if User is VIP

type = Client Script

table = Incident

param = Field = Caller

description = This is an onChange client script that will check to see if the caller is a VIP (based on the VIP field on the user record), if so change the urgency to high.

function onChange(control, oldValue, newValue, isLoading) {

    //If the page isn't loading

    if (!isLoading) {

          //If the new value isn't blank

          if (newValue != '') {

                //If inc is already urgency of high no need to go on

                if (g_form.getValue('urgency') != 1){

                      var caller = g_form.getReference('caller_id');

                          if (caller.vip=='true') {

                                g_form.setValue('urgency', '1');

                          }          

                }

          }

    }

}

If you are already using the default client script: Highlight VIP Caller, you can add in the following line to that client script:

g_form.setValue('urgency', '1');

after this line:

if(caller.vip=='true') {

As-is functionality Caution: The customization described here was developed for use in specific ServiceNow instances, and is not supported by ServiceNow Customer Support. This method is provided as-is and should be tested thoroughly before implementation. Post all questions and comments regarding this customization to our community forum.

                This is the screen I received after I saved the script. Now could someone please let me know how I can test this script whether it is working or not. I mean, how to create a VIP user and how can I login as him retain my login as   admin on the same instance of ServiceNow. Please help!

find_real_file.png

1 ACCEPTED SOLUTION

Harish,



                I did the following:


  • I was not able to find the option VIP for any user. Hence, I first included VIP in my selected list of columns and then sorted it based on its value which said "true".

find_real_file.png


  • I was able to find only one user. So, I created another user by name: sify.servicenow and marked him as a VIP. Again, here I did not have the option of VIP enabled hence, I did a right click and went to the "Form Layout".

find_real_file.png



                From the Available fields I added the "VIP" onto my Selected list, which then gave me an option of using the check box to select him as a VIP user.


find_real_file.png



                  This is the screen where we can see the "VIP" with the check box.


find_real_file.png



  • Now with all your help I was able to check the client script and it worked fine.
  • Please, if it is feasible to select multiple correct answers.

View solution in original post

6 REPLIES 6

vinitha3
Tera Guru

Hi Nandan,



how to create a VIP user - Go to the user table(type sys_user in filter navigator), select any user and select the VIP check box.


find_real_file.png


find_real_file.png



how can I login as him retain my login as   admin on the same instance of ServiceNow - Do you have admin rights, if so open your user record and add the role "Impersonate_user" to your record. Just refresh your browser cache and log in again. Now you can impersonate any active user. you should see the below screen in log in page.


find_real_file.png



Thanks,


Vinitha.K



PS : Please hit Like or helpful or correct answer if it had helped you.


preddy
Kilo Guru

Hi Nandan,



use onChange Client script and select what table you needed and select filed.



function onChange(control, oldValue, newValue, isLoading) {


  var callerLabel = $('label.incident.caller_id');


  var callerField = $('sys_display.incident.caller_id');



  if (!callerLabel || !callerField)


  return;



  if (!newValue) {


  callerLabel.setStyle({backgroundImage: ""});


  callerField.setStyle({color: ""});


  return;


  }


  g_form.getReference('caller_id', vipCallerCallback);


}




function vipCallerCallback(caller) {



  var callerLabel = $('label.incident.caller_id').down('label');


  var callerField = $('sys_display.incident.caller_id');


  if (!callerLabel || !callerField)


  return;



  //check for VIP status


  if (caller.vip == 'true') {


  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, paddingLeft: '30px' });


  callerField.setStyle({color: "red"});


  } else {


  callerLabel.setStyle({backgroundImage: ""});


  callerField.setStyle({color: ""});


  }


}



PS : Please hit Like or helpful or correct answer if it had helped you.