Catalog Client Script to set Values of Dependent Fields

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 11:01 AM
I have a catalog item with a variable set that includes 'business unit' as a reference from the OOB 'business_unit' table, 'business group' and 'business function' both of which are lookup select boxes to a custom table with reference qualifiers dependent on business unit.
In my catalog item, these fields are hidden by UI Policy on all except the catalog task. I have a client script that I want to set the values of these three fields (only on this one catalog item).
My onLoad script is as follows:
function onLoad() {
g_form.setValue('business_unit', 'eacc8ef3db5414d08b6cf77c299619e2', 'Global Operations');
g_form.setValue('business_group', 'Global Operations');
g_form.setValue('business_function', 'b64abb101bf1dc102804ba215b4bcba2', 'Procurement & Corp Purchasing');
}
It sets the business unit and business group fields correctly, but will not set the business function. I have tried setting the last line to
g_form.setValue('business_function', 'Procurement & Corp Purchasing');
with no luck. Thinking the ampersand might be the issue, I changed the value of the choice to 'Procurement Corp Purchasing'. Didn't work. The select box options on business function ARE correct on the form when it loads with the business unit and group loaded, so the right options are available, it just isn't selecting it.
Can anyone give me some other things to try?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 12:54 PM
Since these are references, can you set the value to just the sys_id instead?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 01:01 PM
Thanks for the reply, but no, that didn't work. I've tried it with fieldname: sys_id : name, fieldname: sys_id, and fieldname: value and none of those seem to work for that last variable. The other two work just fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 01:01 PM
To state the obvious, make sure business_function is exactly the name of the variable (no trailing space,...). It's best to use three parameters when setting the value of a select box, even though on lookup the value seems to be the same as the display value (not the sys_id of that record). Did you try another value, or with the & removed
g_form.setValue('business_function', 'Procurement Corp Purchasing', 'Procurement Corp Purchasing');
I don't think it matters, but are your last statements saying that you can manually select this value (so it is displayed in the list?)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 01:13 PM
Thank you for your response! The variable name (business_function) is correct (always a good idea to state the obvious!).
I reset the script to use fieldname variable, value, display value - like below. It still doesn't work.
function onLoad() {
g_form.setValue('business_unit', 'eacc8ef3db5414d08b6cf77c299619e2', 'Global Operations');
g_form.setValue('business_group', 'Global Operations');
g_form.setValue('business_function', 'Procurement Corp Purchasing','Procurement & Corp Purchasing');
}
The label and value of the option are different
And yes, my last statement in the original question indicates that I can manually select the value (it is displayed in the list).