- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2017 01:17 AM
I need to manipulate glideList variable from catalog client script and found 2 post on this
and
https://servicenowgems.com/2016/11/22/clearing-values-on-catalog-glidelist/
This works well when code is directly inserted into client script but we need to call these functions from different client scripts and would like to avoid code duplication.
I created a new UI script with 2 functions
var GlideListHandler = Class.create({
glideListClearValue : function (variable) {
var ref = g_form.resolveNameMap(variable);
if (!ref) {
return;
}
var sourceSelect = $('select_0' + id);
var sourceOptions = sourceSelect.options;
var sourceSelectLength = sourceSelect.length;
for (var i = 0; i < sourceSelectLength; i++) {
sourceSelect.remove(0);
sourceSelect.disabled = true;
sourceSelect.disabled = false;
}
toggleGlideListIcons(id);
if ($(ref + "_unlock").visible()) {
$(ref + '_unlock').click();
$(ref + '_lock').click();
}
},
glideListSetValue : function (variable,listIds,listNames) {
var liDs=[];
var lNames=[];
liDs=listIds.split(',');
lNames=listNames.split(',');
var ref = g_form.resolveNameMap(variable);
if (!ref) {
return;
}
$(ref + '_unlock').click();
for (var i=0;i<liDs.length;i++) {
addGlideListChoice('select_0' + ref, liDs[i], lNames[i]);
}
$(ref + '_lock').click();
},
type: "GlideListHandler"
});
And in catalog client script (on change), I tried this code to clear a glide_list variable called List
if (newValue == 'true'){
var glHandler = new GlideListHandler(g_form);
glHandler.glideListClearValue('List');
}
But this doesn't work as expected : List variable still shows selected values when locked (values disappear when List is unclocked)
Any idea ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 12:25 AM
I found errors in my code
var sourceSelect = $('select_0' + id);
...
toggleGlideListIcons(id);
should be
var sourceSelect = $('select_0' + ref);
..
toggleGlideListIcons(ref);
And this works using UI Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2017 07:13 PM
Hi Patrick, have you marked your UI script as global?
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2017 07:15 PM
You may also want to create another catalog client script which contains an empty definition of a catalog client script and below it the definition if your "class" with the two functions.
You may also want to try out just to declare the functions without using the class prototype approach.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2017 07:15 PM
I hope this helps!
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2017 12:25 AM
I found errors in my code
var sourceSelect = $('select_0' + id);
...
toggleGlideListIcons(id);
should be
var sourceSelect = $('select_0' + ref);
..
toggleGlideListIcons(ref);
And this works using UI Script