Split the value from look up select box field and auto populate in single line text variable

satya30
Tera Contributor

I have a look up select field where I am populating the values of u_code, u_label by seperator (u_code|u_label)
then I have a single text variable which is read only where I need to auto populate the u_code that is getting displayed in the look up select box field.

Here, I cannot change the Look up select box to Reference field.

Thanks in advance.

9 REPLIES 9

yeah i am getting the sys)id of the record in info message
I am not allowed to change the variable type here.

please help me with GlideRecord and get the value of field u_code from that table
I tried and it is not working for me.

sejal1107
Tera Guru

Hi @satya30 

Please try below code

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;  

    // Get the selected value from the lookup select field (assuming it's 'u_lookup_select')
    var selectedValue = g_form.getValue('u_lookup_select'); 

    // Split the value at the separator (assuming format is u_code|u_label)
    var uCode = selectedValue.split('|')[0];  // Extract the u_code part
   alert(uCode);
    // Set the u_code into the read-only text field (assuming it's 'u_code_field')
    g_form.setValue('u_code_field', uCode);
}

If my response helped please mark it correct and helpful.

 

Thanks & Regards,

Sejal

 

Please check and Mark Helpful and Correct if it really helped you.
Thanks & Regards
Sejal Chavan

I tried this way, this is storing the sys_id of the record in the code field.

what needs to be done here?

What is added in 'Lookup value field' for look up select field ?

instead of  

 

 

var selectedValue = g_form.getValue('u_lookup_select'); 

 

 

try using 

 

 

var selectedValue = g_form.getDisplayValue('u_lookup_select'); 

 

For me its showing properly

Screenshot 2025-01-23 at 2.48.22 PM.png

Please check and Mark Helpful and Correct if it really helped you.
Thanks & Regards
Sejal Chavan

getDisplayValue works only for reference fields.

In the look up field it is take u_Code | u_label values to get displayed