Auto Populate Reference field based on another Reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 12:05 PM - edited 08-01-2024 12:08 PM
How can I auto populate a field value based on the value selected on another field? Basically, these are two different fields that are referencing the same table, so we want the value selected for field 1 to be auto populated in field 2.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 08:24 PM
@Austine Please check if there is any reference qualifier applied on the site field. Please refer to https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/script/server-scripting... to know more about reference qualifiers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 09:28 PM
@Sandeep Rajput , Yes, there's a reference qualifier condition in one of those fields. And I am still looking for solution to this task
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 01:18 PM
Hi @Austine ,
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('GetCustomerData');
ga.addParam('sysparm_name','getFieldValue');
ga.addParam('sysparm_field','u_reference_1');
ga.addParam('sysparm_user_id', g_form.getValue('caller'));
ga.getXML(DoSomething);
function DoSomething(response) {
var company = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('company',company);
}
}
Script include:
var GetCustomerData = Class.create();
GetCustomerData.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getFieldValue: function() {
var user = new GlideRecord('x_medt2_ihs_customers');
user.get(this.getParameter('sysparm_user_id'));
if(! user.sys_id){
return false;
}
return user[this.getParameter('sysparm_field')];
}
});
Please mark as helpful/correct if it helps.
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 12:49 AM
Hi @Austine
Did you got a chance to read the below article :
You can give it a try using the Auto Populate Feature as you are dealing with reference fields only.
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.