- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2017 11:11 AM
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.
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());
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 09:05 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 07:07 AM
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:
The messages all have the correct values, but the control is still empty.
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 07:51 AM
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:
- 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?)
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 08:54 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2017 08:35 AM
Rajesh,
u_prefix is already the Display Value for the table.
Thanks,
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2017 09:44 AM
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.
Thanks,
Mel