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,


Thank you for the help.


I have an addInfoMessage in the actual script, and it returns all the records as messages on the page.   It shows both the value and the label and I have verified that the value (sys_id) is correct for the records.



Here is the script with the addInfoMessage line:


while(que.next()) {


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


  g_form.addInfoMessage('label:' + que.u_prefix + ' sys_id:' + que.sys_id);


  }



Here is a screen shot of the form with the massages:


find_real_file.png



The messages all have the correct values, but the control is still empty.



Dave


Hi Dave,



I assume that the values for Subnet before you cleared the choice list were also sys_ids?



I am doing the same method that you are for clearing a choice list and then repopulating the list; the method is working correctly for me.



Based on the information that you have provided, there seems to be only two things that I am doing that are different from you:



  1. I am not setting either the label OR the value to strings when I use the addOption() (My value is NOT a sys_id though. Have you tried keeping the sys_id to string but NOT the label?)
  2. The values being fed into addOption() is coming straight from the GlideAjax, in an array


One final thing, is this Subnet variable configured as a Select Box or a Lookup Select Box?



Thanks,


Mel


rajeshraya
Giga Expert

Dave,



Is the u_prefix column the Display Value on the respective table? If not, please try making it as the Display and try executing your script.



Rajesh


Rajesh,


u_prefix is already the Display Value for the table.



Thanks,


Dave


Hi Dave,



When you find the time, could you provide a screen shot of the variable configuration of your Subnet variable (like the below example)? I think that the root cause may be something in the overall setup of the variable itself. I am not seeing any issues with your script.


find_real_file.png



Thanks,


Mel