Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

catalog variable values in servicenow

v-paulp
Tera Contributor

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,

 

var reports = Class.create();
reports.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    initialize: function() {
    },
    getReportInfo: function() {
        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'
});
 
 
And added that script include in the Reference qualifier of that variable, but it is not working, it still showing all the reports on that variables.
 
vpaulp_0-1713424069316.png

Please let me know where am i making the mistake.

 

Thanks

Pradip Paul

5 REPLIES 5

Ranjit Nimbalka
Mega Sage

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

 

 

Community Alums
Not applicable

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

Hi

Thanks for the reply.

But its not working, still showing all the reports available on our instance

Community Alums
Not applicable

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);

SarthakKashya2_0-1713436724588.png

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

SarthakKashya2_1-1713436831514.png

 

When I add any user who have multiple report it shows like below image

SarthakKashya2_2-1713436892044.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak