How can I populate location automatically and have the ability to change it?

alecwelle1
Kilo Contributor

We are using a client script to be able to populate location automatically when there is a screen pop.  The screen pop happens for us when we get a call and the user pops up, they then click new incident on the users page and it brings them to the incident form.  Originally, the location was not populating, but we wrote a script to populate it.  I will put in the script below to give a reference, but the ulitmate goal is still having the ability to update the location because we also will change a users location to "Remote Office" when they are having problems outside of the office.

 

function onLoad()  

{  

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

}  

function setLocation(caller) {  

if (caller) g_form.setValue('location', caller.location);  

}  

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

You can add a condition to check the current location value:


function onLoad() {


      var location = g_form.getValue('location');


      if(!location) {


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


      }


}



function setLocation(caller) {


      if (caller) g_form.setValue('location', caller.location);


}


View solution in original post

5 REPLIES 5

Sowmya
Tera Contributor

When I use this I am getting sysID as display value can anyone suggest how to populate location using client script