How to set up record producer field to auto-populate information based on selection in a lookup selection box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 12:49 PM
Hi Community. I'm a newbie Sys Admin and no scripting experience but very interested in learning. I have a project to create a record producer where I need to set up certain fields to auto-populate with information from the User table when a User is selected in a lookup select box. Any suggestion on setup is greatly appreciated.
An example is when I select John Smith in the lookup select box, I would like the other field to populate with his Title.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 01:03 PM
Hi Rosie,
Lookup select box should also do in this case Below example is based on user, location should auto populate
You can also try with this below ref in the reference qualifier of the look up select box
javascript:'location.name='+current.variables.located_at
Or check below link-
https://community.servicenow.com/community?id=community_question&sys_id=ec1559a4db2c2f488e7c2926ca961936
Mark correct if my answer has solved your issue and or helpful if my response was worthy.
Thanks,
Ruhi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 05:48 PM
Hi Ruhi,
Thank you so much for the suggestion. I read the article. My two variables are Full Name (lookup) and Current HCM Job Title (reference). How do I plug in these fields in this script, "javascript:'location='+current.variables.your_location_variable"? I tried to plug them in but it didn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 06:39 PM
So this is what I have so far. Trying to follow the article but it's not working.
In the Current HCM Job Title, Reference Qualifier is "javascript:'user.name='+current.variables.full_name"
Default value variable attributes "ref_qual_elements=full_name"
What I want it to do is when the Full Name is populated with a name from the User table, the Current HCM Job Title will auto-populate with the Title of the selected User in the Full Name lookup.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 01:19 PM
Hi Rosie,
There are many ways to do this, best an recommended way is to via Script Include and GlideAjax.
Is there any purpose you are going with Look up select box ? I would suggest you to use reference variable.
Also can you let me know the lookup select box display field name which you selected in the variable ?
Create a Client Callable Script include :-
var GetUserDetailsAjax = Class.create();
GetUserDetailsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function(){
var obj={};
obj.title='';
var id=this.getParameter('sysparm_user_id'); // Getting the sys id of the user
var gr= new GlideRecord('sys_user');
if(gr.get(id)){
obj.title = gr.getValue('title'); // Pulling user title
}
return JSON.stringify(obj);
},
type: 'GetUserDetailsAjax'
});
onChange Client Script :-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var id = g_form.getValue('VARIABLE_NAME'); // lookup select box variable name
var ga = new GlideAjax('GetUserDetailsAjax'); //Name of your script include, make sure script include is client callable
ga.addParam('sysparm_name','getInfo');
ga.addParam('sysparm_user_id',id); // assuming the sys id
ga.getXML(CallBack);
function CallBack(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
var user=JSON.parse(answer);
g_form.setValue('title', user.title); // Title variable name
}
}
Please mark it as helpful or correct based on the impact
Abdul Azeez
