The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How can i copy the contents of one field and duplicate it on another field?

thiraj
Tera Contributor

Hi Team,

I want to copy the contents from one field (String1) and duplicate it on another field (String2) as the default value. Users with access to edit can edit the (String2) field. But by default, (String1) should be the same as (String2).

String1 - u_os_host_name

String2 - u_inventory_name

find_real_file.png

They are both in the same table / form.

All help is appreciated.


Thank you

Regards

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi,



You can do this a couple ways. The first is with an onChange client script to set the value if none already exists. For example:



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


  if (newValue === '') {


      return;


  }


  if (g_form.getValue('u_field2') != '') {


        return; // a value already exists. do not overwrite


  }



  // Copy the value from u_field1 to u_field2


  g_form.setValue('u_field2', g_form.getValue('u_field1'));


}


View solution in original post

10 REPLIES 10

Hi Chuck,



Can i use OncellEdit?