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
09-01-2023 04:46 AM - edited 09-01-2023 07:07 AM
The values that you use in the setValue arguments depend on the field(s) you select in the variable definition for Lookup value field (mandatory) and Lookup label field(s) (optional). So to match closer to your example on a custom table I picked 2 random string fields for the value and label
On this record the String Limit field is populated with "String Limit & Only a Test" and the Return test field is populated with "String Limit & Only a Test!!!" just so it's something different, but these can be the same, or you can leave out the label, and the value field will also show as the label. My setValue for this variable looks like this:
g_form.setValue('lookup_sb', 'String Limit & Only a Test', 'String Limit & Only a Test!!!');
Using the SN Utils Chrome plugin, I can easily verify the variable name and the value and label of the selection - when populated via script or if I select a record manually.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 09:37 AM
Looking at my values/labels in the catalog task (I have since put the ampersand back in the value and label)
and this is my type specification on the variable set variable for the lookup select box:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 10:17 AM
So you are using the Business Function (u_business_function) field on your custom table as the lookup value and lookup label, and there seems to be a record with u_business_function = 'Procurement & Corp Purchasing' (or maybe there's a trailing space there?) when you select it manually. What I'm not following is your earlier screenshot showing a 'Value' and 'Label' column and your mention of putting the ampersand back in both. Are these fields also on the same custom table, populated the same as the business function field in this case? Is u_business_function a string field? Have you tried a different u_business_function value/record in the script setValue?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 10:36 AM
Yes, the fields are all on the same custom table. I had removed the ampersand from the value of 'Procurement & Corp Purchasing' at one time thinking that character might be the problem. (So the value was 'Procurement Corp Purchasing' and the label was 'Procurement & Corp Purchasing' but both the value and label have the ampersand now.) Business function and Business group are both string fields. Business Unit is the only reference field. All fields are present on the custom table. I did try a different value/record in the script for business function and it still didn't work.
I have opened a support case as I must be missing something completely. Thank you so much for your help/suggestions!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 06:49 AM
Another thing to consider is that this script is actually working to set the variable value, but there is another Catalog Client Script or Catalog UI Policy that is also affecting/clearing the value of this variable.