- 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-04-2018 02:10 PM
Also forgot to mention that I have a second Client Script that runs onChange to do the same behavior when the requested_for value changes, as users can request on behalf of others.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2018 08:58 AM
Bump- Would love to get some feedback on this 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2018 09:02 AM
Working sir, please wait and will provide a reply shortly 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2018 09:08 AM
You can call the script include from reference qualifier of list collector variable directly by passing on the requsted_for variable value as input to one of the function in your script include
eg, your script include name is "myClass"" and your function name inside the script include is "myFunc"", you can put code liek
javascript:new myClass().myFunc(current.variables.requested_for);