When a value is selected in a reference type item

user_ms
Tera Expert

When a value is selected in a reference type item, I want to display another item of the record selected in the reference type item in a read-only string column.

 

reference_column_a : Reference type item
reference_column_b: Display another item of the record selected in the reference type item

 

Currently, it is executed using a client script, and sys_id is returned to reference_column_b.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var reference_column_a = g_form.getValue('reference_column_a');
g_form.setValue('reference_column_b', reference_column_a);
}

 

It would be helpful if you could tell me how.

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @user_ms 

If you're working with Catalog Item, you can leverage the Auto-populate feature within the Variable configuration.

Screenshot 2023-11-06 at 11.37.18.png

 

In the other hand, you can do an AJAX call > query to the table of the first reference field > get the value sys_id of the second reference field.

 

You're also able to achieve this using the below API.

getReference(String fieldName, Function callBack)

Sample.

function onChange(control, oldValue, newValue, isLoading) {
    g_form.getReference('<reference_field_1>', populateValue); // doAlert is our callback function
}
 
function populateValue(reference_field_1) { // reference is passed into callback as first arguments
   g_form.setValue('<field_name>', reference_field_1.getValue('<reference_field_2>'));
}

 

Let me know if it works for you.

 

Cheers,

Tai Vu

View solution in original post

4 REPLIES 4

Tai Vu
Kilo Patron
Kilo Patron

Hi @user_ms 

If you're working with Catalog Item, you can leverage the Auto-populate feature within the Variable configuration.

Screenshot 2023-11-06 at 11.37.18.png

 

In the other hand, you can do an AJAX call > query to the table of the first reference field > get the value sys_id of the second reference field.

 

You're also able to achieve this using the below API.

getReference(String fieldName, Function callBack)

Sample.

function onChange(control, oldValue, newValue, isLoading) {
    g_form.getReference('<reference_field_1>', populateValue); // doAlert is our callback function
}
 
function populateValue(reference_field_1) { // reference is passed into callback as first arguments
   g_form.setValue('<field_name>', reference_field_1.getValue('<reference_field_2>'));
}

 

Let me know if it works for you.

 

Cheers,

Tai Vu

@Tai Vu 
Thank you for your advise.

I was able to execute it successfully.

Hi @user_ms 

If my comment was helpful, feel free to mark it as a solution. 😁

 

Cheers,

Tai Vu

user_ms
Tera Expert

@Tai Vu 

Thank you for your advice.

I was able to execute it successfully.