- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 03:33 PM
I am running the script below in both a record produce page and on a form. The record producer page has a setting you can turn on or off to not show duplicates. In the form you do not. The values in the choice list are not duplicates when you look at the full record, but one value in the record can be duplicated when not in combination with the other values in the record.
I am trying to get rid of the duplicates in the "u_secondary_issue_category' field. Does anyone have any idea how to do this??
function onChange(control, oldValue, newValue, isLoading) {
if(newValue == oldValue){
return;
}
//remove all items from subcat drop down to start
// Used the g_form.clearOptions() function instead of g_form.removeOption() function
g_form.clearOptions('u_secondary_issue_category');
//build a new list of dependent options
var gp = new GlideRecord('u_novitex_issue_dictionary');
gp.addQuery('u_primary_system', newValue);
gp.query();
while(gp.next()){
g_form.addOption('u_secondary_issue_category', gp.u_sub_system, gp.u_sub_system);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 09:20 PM
Its seems like choice table already contains duplicates. You need to build your own logic to remove duplicates. Try below code.
function onChange(control, oldValue, newValue, isLoading) {
if(newValue == oldValue){
return;
}
//remove all items from subcat drop down to start
// Used the g_form.clearOptions() function instead of g_form.removeOption() function
g_form.clearOptions('u_secondary_issue_category');
//build a new list of dependent options
var previousValue = '' ;
var gp = new GlideRecord('u_novitex_issue_dictionary');
gp.addQuery('u_primary_system', newValue);
gp.orderBy('u_sub_system');
gp.query();
while(gp.next()){
var currentValue = gp.u_sub_system ;
if(currentValue != previousValue){
g_form.addOption('u_secondary_issue_category', currentValue, currentValue);
}
previousValue = currentValue;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 09:10 PM
No Change. I already add that string starting on line 2. I added it again on line 12.
Jim Calhoun, Solutions Engineer, MCITP — Customer Focused Innovations
205 Michigan Ave<x-apple-data-detectors://1/> I ste. 300 I Chicago, IL I 60601
M: 708-285-5986<tel:708-285-5986>
Jim.Calhoun@novitex.com<mailto:Jim.Calhoun@novitex.com> |www.novitex.com<http://www.novitex.com/> | About Novitex<http://bit.ly/1j3tBOU>
For support please open an Incident ticket in ServiceNow<https://novitextest.service-now.com/>.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 09:20 PM
Its seems like choice table already contains duplicates. You need to build your own logic to remove duplicates. Try below code.
function onChange(control, oldValue, newValue, isLoading) {
if(newValue == oldValue){
return;
}
//remove all items from subcat drop down to start
// Used the g_form.clearOptions() function instead of g_form.removeOption() function
g_form.clearOptions('u_secondary_issue_category');
//build a new list of dependent options
var previousValue = '' ;
var gp = new GlideRecord('u_novitex_issue_dictionary');
gp.addQuery('u_primary_system', newValue);
gp.orderBy('u_sub_system');
gp.query();
while(gp.next()){
var currentValue = gp.u_sub_system ;
if(currentValue != previousValue){
g_form.addOption('u_secondary_issue_category', currentValue, currentValue);
}
previousValue = currentValue;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 09:26 PM
That worked, thank you very much. I will also look at the client GlideRecord.
Jim Calhoun, Solutions Engineer, MCITP — Customer Focused Innovations
205 Michigan Ave<x-apple-data-detectors://1/> I ste. 300 I Chicago, IL I 60601
M: 708-285-5986<tel:708-285-5986>
Jim.Calhoun@novitex.com<mailto:Jim.Calhoun@novitex.com> |www.novitex.com<http://www.novitex.com/> | About Novitex<http://bit.ly/1j3tBOU>
For support please open an Incident ticket in ServiceNow<https://novitextest.service-now.com/>.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 09:22 PM
Note: you are using GlideRecord in client script and it is making synchronous server call. Have a look at client GlideRecord.
http://wiki.servicenow.com/index.php?title=Client_Side_GlideRecord#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 09:33 PM
Hi Jim,
Can you please close this thread by marking the replies Correct/Helpful.