Script Include for Array to add options to Choice List field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 06:32 AM
Hello,
I was reading some other posts about having a Script Include to pass an array to a client script and add the options into a choice list field. I want to try this first in the Catalog Item and then apply it to a Catalog Task as there is where I need to populate the drop-down or choice list field.
I have a variable set (MRVS) where I have a column named Part Number so the number of part numbers are entered by the end user, so it can be more than 1.
I have the following client script where I can get the values from the variable set, but I can't populate the choice list with those values.
I'm pretty much new in Script Include so I really appreciate any help.
function onSubmit() {
//Type appropriate comment here, and begin script below
var jsonStr = g_form.getValue('commodity_details');
var objList = JSON.parse(jsonStr);
var part_numbers_array = [];
for (var i = 0; i < objList.length; i++) {
part_numbers_array.push(objList[i].pr_number.toString());
g_form.addOption('u_eu_mdr_part_numbers', part_numbers_array, part_numbers_array);
g_form.setValue('description', part_numbers_array);
}
alert(part_numbers_array);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 07:21 AM
When using addOption, the user is only going to see the added choice values while on the form when the script is run, so doing this onSubmit does not make sense. You'll want to change this to an onLoad script. You won't be able to test this on the request form since the MRVS will be empty when the request form is loaded, so go ahead and submit a request with a populated MRVS, then run this script onLoad and applies on Requested Items, and/or applies on Catalog Tasks, making sure the MRVS is included in the variables shown on this Catalog Task. In your script, since you are using addOption inside of the for loop, it should look like this:
g_form.addOption('u_eu_mdr_part_numbers', objList[i].pr_number.toString(), objList[i].pr_number.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 09:36 AM
That worked fine. Thanks. It copied the values to the drop-down list. I changed the client script to onLoad, and if I edit the MRVS from the Catalog Task it also copies the values to my choice list field.
Do you know how to copy a choice list (values) from Catalog Task table to a new table where I have another choice list field? It seems that I can do it from the Dictionary by choosing the table and the field, but my "EU MDR PART Numbers" field is not show up.
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 12:36 PM
The Choice field is only going to show fields on the sc_task table, not variables - which don't really exist on the sc_task table, they are an object accessible via this table. The variable inside a MRVS adds another layer of complexity to doing this. Maybe you could add a record to the sys_choice table for each part number entered in each row of the MRVS for each of these requests, then the other table would reference the sys_choice table to get the list of all part numbers that have been entered on all requests?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2022 10:01 AM - edited 12-13-2022 10:02 AM
I found another workaround. I created another customized table that inserts the part numbers and the task number via BR rule in the Catalog Task, then I change the field from choice list to reference field and it is pointing to this new table where I'm storing all the part numbers.
The thing now is that I want to filter the reference field and show only the part numbers where the task no is equal.