- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2018 02:07 PM
Hi all,
Having an issue I hope people can help me out with!
I want to set a list collector reference qualifier based on a field on the request form.
I want to return all Configuration Items that have a Management Group that the user in the requested_for variable is a part of. To do this, I am attempting to set my reference qualifier query via a Client Script in a variable within a Script Include. I will use that same Script Include to get the saved value in the Reference Qualifier field of the variable.
My issue: It does not seem like variables are saving in the Script Include. It seems like it reinitializes every time the Script Include is called and deletes the value in the variable. I am wondering if I am doing this correctly, or if there is possibly a better way to do this?
Here is my Client Script which
function onLoad() {
var groupString = "";
var newValue = 'requested_for';
var gr = new GlideRecord ('sys_user');
gr.addQuery ('sys_id', newValue);
gr.query();
while (gr.next()){
var group = new GlideRecord ('sys_user_grmember');
group.addQuery ('user', gr.sys_id);
group.query();
while (group.next()){
groupString += group.sys_id+",";
}
groupString = groupString.substring(0,groupString.length-1);
}
var myLimit = "location=123c49b037d0200044e0bfc8bcbe5dd3^ORlocation=deeb202edbb31600f0727aa9bf9619f3^ORlocation=daeb202edbb31600f0727aa9bf9619f5^install_status!=7^virtual=true^u_management_group.sys_idIN"+groupString;
var limit = new GlideAjax('ServerRebootLimitCIs');
limit.addParam('sysparm_name','setLimit');
limit.addParam('sysparm_limit',myLimit);
limit.getXML(doSomething);
function doSomething(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
}
}
My Script Include:
var ServerRebootLimitCIs = Class.create();
ServerRebootLimitCIs.prototype = Object.extendsObject(AbstractAjaxProcessor, {
limit: "",
getLimit: function(){
return this.limit + "";
},
setLimit: function(){
this.limit = this.getParameter('sysparm_limit');
},
type: 'ServerRebootLimitCIs'
});
I would love some guidance with this or if anyone has a better way of implementing this type of functionality 🙂
Thanks!
Emma
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2018 09:00 PM
My bad,
I thought field is of reference type where you want to set the reference qualifier, but it turned out to be the list collector type.
Please see below link to configure the filter condition for list collector type of variable
https://community.servicenow.com/community?id=community_question&sys_id=08720feddb98dbc01dcaf3231f96196a
If you still want list collcetor to work with reference qualifier, you need to add "glide_list" attribute to variable
Once done, your variable will be looking list a watch list kind of field on incident form
Now, select the user in requested for field and CI field should show you filtered data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2018 07:49 AM
Deepak, thank you for all your help on this. I ended up going with a Client Script that I will post below that I found here
function clear(){
var varName = 'lstColSrvName';
var rightBucket = gel(varName + '_select_1');
var selectedOptions = rightBucket.options;
var length = selectedOptions.length;
for(var i = 0; i < length; i+=1){
//Check for the item to add here based on sys_id
var value = selectedOptions[i].value;
rightBucket.remove(value);
}
}
//Apply a filter to the list collector variable
var collectorName = 'lstColSrvName';
//Try Service Portal method
try{
var myListCollector = g_list.get(collectorName);
myListCollector.reset();
myListCollector.setQuery(myLimit);
}
//Revert to Service Catalog method
catch(e){
//Reset the filter query
window[collectorName + 'g_filter'].reset();
window[collectorName + 'g_filter'].setQuery(myLimit);
window[collectorName + 'acRequest'](null);
}
}