Client Script to auto populate field based on another field not working

User393503
Tera Expert
I want to display the 'parent' value in the 'project' field based on the budget. I tried a getReference and that kept returning the sys id. How do I return the value correctly using displayBox method or getDisplayValue?
 
 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var budget1 = g_form.getDisplayBox('parent').value;
   


 
   
g_form.setValue('project', budget1.parent);
7 REPLIES 7

dhanrajb
Tera Guru

Hi @User393503 ,

 

Try this code and make sure the backend value of the fields are correct.

 

var budget1 = g_form.getDisplayValue('parent');
g_form.project = budget1;

 

 

Regards,

Dhanraj

dgarad
Giga Sage

Hi @User393503 

Please try with the script below.



function onChange(control, oldValue, newValue, isLoading) {

 

    var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function

 

}

 

function doAlert(caller) { //reference is passed into callback as first arguments

 

  g_form.setValue('email',caller.email);

 

  g_form.setValue('phone',caller.mobile_phone);

 

  g_form.setValue('phone',caller.location);

 

}

Please change the variable name 

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Sandeep Rajput
Tera Patron
Tera Patron

@User393503 Please update the client script as follows.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var budget1 = g_form.getReference('budget', callback);
   
function callback(budget1){
g_form.setValue('project', budget1.parent);
}
}

This script returns the sys_id. I want the display value to show.