- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2017 03:45 PM
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
They are both in the same table / form.
All help is appreciated.
Thank you
Regards
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2017 03:51 PM
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'));
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2017 03:51 PM
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'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2017 04:21 PM
Hi Chuck,
I gave it a try and it does not seem to work!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2017 04:43 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2017 04:52 PM
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