Autofill Location based on User
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2013 12:15 PM
Hey all.
I am very green when it comes to Service-Now and particularly Java Script (I'm an IT Admin, not a programmer 🙂 but my company has tasked me with setting up some portions of our new Service Now setup.
What I am trying to do is setup a script that will pull a user's location (as we have several offices around the world) once that user is selected.
To be more clear, we have a "leaver" app we are setting up for HR so that when a user leaves the company, they are able to go through a record producer window and select the username (which pulls from sys_user). I have created a Location field within the main "Leaver" window, and am wondering what type of client scripting would be needed to make it so that when the user is selected, it will autopopulate the location they are at within the location field.
We do have this setup for our "incident" request app, but the diffrerence there is that it autopopulates your own user account automatically on opening the app.. so you open the app, and whoever you're logged in as it will autopopulate that user name and at the same time populate their email address and location in lower fields. I looked to see how this functionality works in the client scripting, but again, I'm no programmer so I can't really figure out how to alter that code to make it work for the leaver process.
Would anyone be able to give me a couple pointers? If I'm unclear please let me know and I will try to give more details.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2013 02:05 PM
You can simply add something like:
current.location = producer.caller.location;
in the script portion of your record producer.
where i'm assuming that the user field in the record producer is called "caller", the location of the user is called "location" under the user record and the location in the leaver apps is called "location".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2013 02:22 PM
Hey Marc,
Thank you for your reply.. I was incorrect however. The leaver process we have setup is a simple catalog item.. not sure why I thought it was in record producer..
Does what you wrote apply for a catalog entry as well? It seems based on the incident items that there is more to the syntax needed..
In incident, this is the code that is showing:
function onLoad() {
if (!g_form.getControl('location'))
return;
var caller = g_form.getReference('caller_id', setLocation);
}
function setLocation(caller) {
if (caller)
g_form.setValue('location', caller.location);
g_form.setValue('u_phone_number', caller.phone);
g_form.setValue('u_email', cal
I assume that this is what's being run onLoad to fill out the location and email information and phone number as well it would seem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2013 02:40 PM
just to make sure i understand correctly, can you provide prints reen of the screen where you want to autofill the location?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2013 03:00 PM
If you look at the screenie, you can see the first two fields are populated manually.. the only one really that we need to populate automatically is the location. The person in HR would specify the user name based through the drop down listing and then based on the user they select, the location should be entered automatically, is the idea.