- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2014 08:32 AM
I am sure this must have been answered by now, but I can only find where the fields are being populated from the current user logged in.
My client wants to have a form section that list all the information about a selected user. I do understand the there is info box is next to the listed user, that shows all the information they are looking for, but they need this for printing reasons.
Full Name Field -> Referenced -> User
I am thinking I could try a client script - onChange -> LXK Full Name
but I am not sure how to set the value of the other fields from LXK Full Name.
I know if I was looking for the information from the logged in user, it would be a simple script.
javascript:gs.getUser().getManagerID()
Would it be something like this?
var fullname = 'u_fullname';
var manager = 'u_manager';
fullname = g_form.tableName + '.' + fullname;
g_form.setValue('manager' , 'fullname.getManagerID()' );
Give me a idea of how to do one and I can figure out the rest.
Thanks
Solved! Go to Solution.
- Labels:
-
Best Practices

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2014 08:50 AM
I think if you need it on the form for printing reasons the best practice is just to drill into the reference field while personalizing the form to add the related fields. The autofill would happen automatically in that case with no additional scripting necessary.
The only reason you wouldn't want to do that is if you wanted your users to be able to change the information in the fields being displayed...i.e. the user information to populate might not always be the same as the referenced record so you want to default it but allow it to be changed.
If that's the case, the best practice is to use an onChange client script with an asynchronous 'getReference' call. This SNGuru article explains this method...
http://www.servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/
Here's a simplified example...
//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);
function popCallerInfo(caller){
//Value setting section
//If the form isn't loading and the new value isn't equal to the old value
if(!isLoading && newValue != oldValue){
g_form.setValue('location', caller.location);
//Set additional values here...
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2014 08:44 AM
Hi,
You wouldn't need to script anything if you just add the derived fields from the user lookup record to the form.
Displaying Information from Other Records - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2014 08:50 AM
I think if you need it on the form for printing reasons the best practice is just to drill into the reference field while personalizing the form to add the related fields. The autofill would happen automatically in that case with no additional scripting necessary.
The only reason you wouldn't want to do that is if you wanted your users to be able to change the information in the fields being displayed...i.e. the user information to populate might not always be the same as the referenced record so you want to default it but allow it to be changed.
If that's the case, the best practice is to use an onChange client script with an asynchronous 'getReference' call. This SNGuru article explains this method...
http://www.servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/
Here's a simplified example...
//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);
function popCallerInfo(caller){
//Value setting section
//If the form isn't loading and the new value isn't equal to the old value
if(!isLoading && newValue != oldValue){
g_form.setValue('location', caller.location);
//Set additional values here...
}
}