- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have a form field and need to have an option already selected when the form loads. So, I created an onload client script as per the code below. However, the code doesn't work. The field that should be set to the option is a reference field. Could you help me if I'm missing something in my code?
function onLoad() {
if (!g_form.getValue('item_set')) {
g_form.setValue('item_set', '408aa0481bd7d910a9bc0fa0f64bcb6d');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Ariomar de Deus ,
You are saying the field is choice field, but you are setting the value as sysid like its a reference. Please verify once.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
So your client script is at catalog and not variable set? Can you confirm there is no client script at variable set/ catalog item level conflicting with this?
Onchange client scripts also work on load if script is written in OnLoad block.
There can be a UI policy conflicting as well.
Overall, your script is correct, also make sure if you are checking on portal the UI type is set to All
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
If you want to set it on load , you can add this sys_id in default value.
Make sure the sys_id of the valid record from the table the field is referring to.
Also once try without the if condition if above 2 don’t work.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I tested removing the if and it didn't work, when I set the option to the default value I can't because the field is inserted in a variable set and regarding the sysID the value is correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
So your client script is at catalog and not variable set? Can you confirm there is no client script at variable set/ catalog item level conflicting with this?
Onchange client scripts also work on load if script is written in OnLoad block.
There can be a UI policy conflicting as well.
Overall, your script is correct, also make sure if you are checking on portal the UI type is set to All
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Ariomar de Deus ,
You are saying the field is choice field, but you are setting the value as sysid like its a reference. Please verify once.