We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Dotwalk in Glide AddQuery Possible?

johansec
Tera Guru

Is it possible to dotwalk in an Addquery filter conditon?

Here is what I am trying to do.

I am attempting to get the top 5 most frequently requested items by the current user. I was able to get this to work by using the opened by field on the RITM but I would like to dotwalk to the parent and get only RITM where the parent Req's field 'Requested_for' is the current user. Heres what I have so far.

data.frequentItems = [];

var currentUser = gs.getUserID();

var count = new GlideAggregate('sc_req_item');

count.addQuery('opened_by', gs.getUserID());     // THIS IS WHERE I NEED TO GET request.requested_for

count.addAggregate('COUNT', 'cat_item');

count.orderByAggregate('count', 'cat_item');

count.chooseWindow(1, 5);

count.query();    

while (count.next()) {

        var itemRecord= count.cat_item.getRefRecord();

        var itemCount= count.getAggregate('COUNT', 'cat_item');

        var item = {

                                                sys_id: itemRecord.sys_id.getDisplayValue(),

                                                picture: itemRecord.picture.getDisplayValue(),

                                                name: itemRecord.name.getDisplayValue()

                                            }

        data.frequentItems.push(item);

}

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee

Hello Corey,



Yes you can dot-walking at addQuery level i.e count.addQuery('request.requested_for', gs.getUserID()); Below is the sample code I tried on my instance.





var currentUser = gs.getUserID();


var count = new GlideAggregate('sc_req_item');


count.addQuery('request.requested_for', gs.getUserID());     // THIS IS WHERE I NEED TO GET request.requested_for


//count.addAggregate('COUNT', 'cat_item');


//count.orderByAggregate('count', 'cat_item');


//count.chooseWindow(1, 5);


count.query();  


while (count.next()) {


      gs.addInfoMessage(count.request.number);


}


View solution in original post

1 REPLY 1

Pradeep Sharma
ServiceNow Employee

Hello Corey,



Yes you can dot-walking at addQuery level i.e count.addQuery('request.requested_for', gs.getUserID()); Below is the sample code I tried on my instance.





var currentUser = gs.getUserID();


var count = new GlideAggregate('sc_req_item');


count.addQuery('request.requested_for', gs.getUserID());     // THIS IS WHERE I NEED TO GET request.requested_for


//count.addAggregate('COUNT', 'cat_item');


//count.orderByAggregate('count', 'cat_item');


//count.chooseWindow(1, 5);


count.query();  


while (count.next()) {


      gs.addInfoMessage(count.request.number);


}