Client script doesn't work as it should
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 11:44 AM
I have two reference fields, but one will be hidden and the other will be visible. When the visible field is filled in, it should automatically fill in the other with the same information. To do this, I created a client script, but it doesn't work. Could someone help me?
function onSubmit() {
var categoria = '00000022_categoria';
g_form.setValue('kb_category', categoria);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 09:06 PM
Since both fields are reference fields it store the sys_id of the table.
You can create a onChange client script for visible field and upon changes set the field value to the hidden field as below. I believe both field are referring to the same table.
var cat=g_form.getValue('u_visible_field');
g_form.setValue('u_hidden_field', cat);
Regards,
Sourabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 10:06 PM
onSubmit is not the right way for this case:
- The onSubmit event triggers when the form is submitted, but you likely want the hidden field to be populated as soon as the visible field is filled.
You're setting a hardcoded value ('00000022_categoria') instead of copying the value from another field:
- If you want to copy the value from the visible reference field, you need to use g_form.getValue().
Please mark correct/helpful if this helps you!