catalog variable values in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 02:12 AM
Hi
There are two variables on a catalog item " select_owner_of_the_reports" and "selects_the_reports_name'.
I want only those reports should show to "selects_the_reports_name" variable where the the created by user is the user on " select_owner_of_the_reports" variable.
I have written a script include for this,
Please let me know where am i making the mistake.
Thanks
Pradip Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 02:29 AM
Hi @v-paulp ,
1. Update reference qualifier as javascript: new reports().getReportInfo(current);
2. please try below script :-
var reports = Class.create();
reports.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {
},
getReportInfo: function(current) {
var value = current.variables.select_no_of_reports;
var owner = current.variables.select_owner_of_the_reports;
var answer = [];
var gr = new GlideRecord('sys_report');
gr.addQuery'sys_created_by'', owner);
gr.query();
while (gr.next()) {
answer.push(gr.getValue('title'));
}
var qry = 'sys_idIN' + answer;
return qry;
},
type: 'reports'
});If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Ranjit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 02:38 AM - edited 04-18-2024 02:40 AM
Hi @v-paulp ,
Can you please update the reference qualifiers as -
javascript: new reports().getReportInfo(current);
And script include like
var reports = Class.create();
reports.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {
},
getReportInfo: function(current) {
var value = current.variables.select_no_of_reports;
var owner = current.variables.select_owner_of_the_reports;
//if (value == 'Multiple Reports') {
var answer = [];
var gr = new GlideRecord('sys_report');
gr.addQuery('created_by_user', owner);
gr.query();
while (gr.next()) {
answer.push(gr.getValue('title'));
}
var qry = 'sys_idIN' + answer;
return qry;
//}
},
type: 'reports'
});
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 03:08 AM - edited 04-18-2024 03:40 AM
Hi
Thanks for the reply.
But its not working, still showing all the reports available on our instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 03:41 AM - edited 04-18-2024 04:44 AM
Hi @v-paulp ,
I tried it on my instance now it is working fine for me
In you variable who is reference to sys_report table add Reference Qualifier as Advance - javascript(add Colon here':', when I tried to add it is adding like : you only need to add colon(':')) new reports().getReportInfo(current);
In Script Include add below code
var reports = Class.create();
reports.prototype = {
initialize: function() {
},
getReportInfo: function(current) {
gs.log("Get Variable = " + current.variables.select_report);
gs.log("Get Variable select_user = " + current.variables.select_user);
// var value = current.variables.select_no_of_reports;select_user
var owner = current.variables.select_user;
//if (value == 'Multiple Reports') {
var answer = [];
var gr = new GlideRecord('sys_report');
gr.addQuery('created_by_user', owner);
gr.query();
while (gr.next()) {
gs.log("Inside hWhile = " + gr.getValue('sys_id'));
answer.push(gr.getValue('sys_id'));
}
var qry = 'sys_idIN' + answer;
return qry;
//}
},
type: 'reports'
};
Result
When I add any user who have one report it shows like below image
When I add any user who have multiple report it shows like below image
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
