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

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'));


}


Hi Chuck,



I gave it a try and it does not seem to work!


Where are you editing these from?



FYI - The example I gave was not meant to be copy/paste. You need to put your field names in there. If you can share the field names and the existing client script you have tried, I can take a better look and give you a more prescribed solution.


Hi Chuck,



Yes i did change the fields to what i have used. The reason i said it is not working is because i have to save the form for the (Field2) to change (copy / duplicate) from (Field1). I want it to change as soon as the (Field1) is entered. Is this possible? If not i can manage with your solution. Your solution works but it does not meet my requirements. I just want it to change to the default value of (Field1) and that should be fixed until someone with access can change the (Field2).



Thank you Chuck