Complex Query to retrieve all RITMS for which the current user is assigned to approve

jamesmcwhinney
Giga Guru

Are there any GlideRecord query gurus out there that could assist with writing a query?

I am trying to write a glide query to get all requested items for which any of the following is true:

- The current user has an approval request associated with the RITM

- The current user has an approval request associated with the parent request

- The current user is the requested for or requested by user for the parent request

- The RITM field "department_it" is set to true

Would any one have an insight on how to perform this?

Here is what I have so far (not working):

var currentUserID = gs.getUserID();

//Where RITM is in IT catalog

var qc = current.addCondition("u_department_it", "true");

//Where user is an approver of the Request

var req = current.addJoinQuery('sc_request','request', 'sys_id');

var reqapp = req.addJoinQuery('sysapproval_approver','sys_id', 'sysapproval');

reqapp.addOrCondition('approver', currentUserID );

//Where user is the requested by for the request

reqapp.addOrCondition('opened_by', currentUserID );

//Where user is the requested for for the request

reqapp.addOrCondition('u_request_requested_for', currentUserID );

//Where user is an approver of the RITM

var ritmapp = current.addJoinQuery('sysapproval_approver','sys_id', 'sysapproval');

ritmapp.addOrCondition('approver', currentUserID );

7 REPLIES 7

I don't know why you're taking this approach -- you're actually making MUCH more expensive queries (yes, multiple queries -- that's what ^NQ does) with this.



Can you explain?


Thanks, for some reason I thought that method would be faster but I suppose not.


It does seem to work, but like you said, its slow.



Is there no equivalent of an addOrJoinQuery ?



As far as what I am trying to accompish, I just posted a reply to Jordan a little higher in the thread.


Thanks again for helping with this!


You may want to take your queries for the RITM records where the user is an approver of the RITM or it's parent and put them in a function that iterates through them and adds their sys ids to an array and then returns that array, then you can use a condition like "sys_idINjavascript: function()" and add your other conditions like you normally would.