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

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);


}


Thank you Michael, this worked perfectly.



Thanks,


Alec Welle


SanjivMeher
Kilo Patron
Kilo Patron

Hi Alec,



Instead of onLoad script, it should be an onChange script. The onChange field should be set to Caller.



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



function setLocation(caller) {


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


}



So that it covers all the scenario



When caller is selected, your location will be set


If you want you will be able to change the location to another location and there wont be any impact


If the caller is changed again, the location will change accordingly.



If you write, onLoad, it mayn't work well, when caller is changed.



Please mark this response as correct or helpful if it assisted you with your question.

wild_
Giga Contributor

I was recently reviewing updates from London and noted a change that appears to affect the best practices plugin (com.snc.bestpractice.incident). This is why i found this question.

 

The Best Practice solution is to use onChange for the caller_id field of your incident form. 

if the newValue is blank, then it blanks out the location field.

It then uses the code referred to by Sanjiv.

 

there seems to be some new checking against g_form.isLiveUpdating in the newer script version from London.