Issue adding options via client script to Reference type choice list

davewilkerson
Tera Expert

I have a client script that uses GlideAjax to call a script include and return a comma delimited list.

I use that list to create a GlideRecord with an addQuery using IN.

I get back the records I expect and loop through them.

This is where I run into an issue.

On the form I have a control that is a Reference type to a custom table.

Under Choice List Specification, the control is set to "Dropdown with -- None --"

By default it displays all of the records in that table (there are only 7) when you put focus on the field.

find_real_file.png

In the client script I can run this and it removes all of the option in the select

g_form.clearOptions('u_subnet');

when I try to add only the valid options back using the records from the GlideRecord, it will not add any options back.

g_form.addOption('u_subnet', que.sys_id.toString(), que.u_prefix.toString());

find_real_file.png

I have tried it without the toString() function but it does not matter.

Any ideas on why this doesn't work, or if there is a different way to add the options if it is a Reference field vs. a normal Choice List?

Thanks,

Dave

1 ACCEPTED SOLUTION

Melinda,


I have a HI ticket and they referred me to PRB652494 - "Reference Choice list can't add options via addOption()"



Here was his response:



Hello Dave,


My name is Gustavo, and I am the support engineer assigned to assist you with this incident opened on your behalf. The addOption function does not work with reference choice lists as has been documented in PRB652494. I don't have any better options for you but you may want to post on the community to see if anyone else has tried something similar. I am setting this incident in a state of solution proposed. Please let me know if you have any further questions.





I did code a work around,


I created a new string field (CIDR Ref Qualifier) on the form,   I populate that field (CIDR Ref Qualifier) from the GlideRecord with a comma delimited list.


On the Subnet field I set the Reference Qual to javascript:"u_prefixIN" + current.u_cidr_ref_qualifier.toString();



This works on the load of the form, but not in subsequent changes to the field(CIDR Ref Qualifier)



To handle the rebinding based on fields changing, I created a Client script with the following line to force update the binding on the field.



updateChoiceList_u_subnet('', '', '', false);



There is a function for each choicelist to force an update in the genereated javascript on each page.



It is not the way I wanted to get this to work, but it is the best way I have figured out so far.





Thanks for the help with this issue.



Dave Wilkerson


View solution in original post

11 REPLIES 11

Melinda,


I have a HI ticket and they referred me to PRB652494 - "Reference Choice list can't add options via addOption()"



Here was his response:



Hello Dave,


My name is Gustavo, and I am the support engineer assigned to assist you with this incident opened on your behalf. The addOption function does not work with reference choice lists as has been documented in PRB652494. I don't have any better options for you but you may want to post on the community to see if anyone else has tried something similar. I am setting this incident in a state of solution proposed. Please let me know if you have any further questions.





I did code a work around,


I created a new string field (CIDR Ref Qualifier) on the form,   I populate that field (CIDR Ref Qualifier) from the GlideRecord with a comma delimited list.


On the Subnet field I set the Reference Qual to javascript:"u_prefixIN" + current.u_cidr_ref_qualifier.toString();



This works on the load of the form, but not in subsequent changes to the field(CIDR Ref Qualifier)



To handle the rebinding based on fields changing, I created a Client script with the following line to force update the binding on the field.



updateChoiceList_u_subnet('', '', '', false);



There is a function for each choicelist to force an update in the genereated javascript on each page.



It is not the way I wanted to get this to work, but it is the best way I have figured out so far.





Thanks for the help with this issue.



Dave Wilkerson


Ah I see, I had a feeling that the addOption() may not have been working due to the variable being a Choice Select Box/reference type. Perhaps you should mark your own response as the correct answer to this thread?



- Mel