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.

Related List in Users for their RITMs

VernYerem
Tera Expert

Hello! Looking to add a related list to Users to show what RITMs they've requested. Creating the Relationship and adding it to users is easy enough. But it looks like I need to add "Query with" in the relationship, otherwise it just shows all RITMs in the related list within the user record.

 

I believe I'll need to query the RTIMs "requested for", but kind of lost from there. Any guidance would be great!

1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hey @VernYerem,

 

No need to create a new relationship here, use the Requested Item > Requested For from the available list.

JamesChun_0-1709686644697.png

 

Cheers

View solution in original post

4 REPLIES 4

eagle18
Tera Contributor

HI @VernYerem 

 

you need to create a new relationship and add query on the  requested for field. The OOB field uses requested_for

Check your RITM or REQ for the correct user field and add this line to the query

current.addQuery('requested_for', parent.requested_for);

 

eagle18_0-1709686128425.png

eagle18_2-1709686161270.png

 

Thanks

Hope this helps. Please mark the answer as correct/helpful if this solves your issue.

 

James Chun
Kilo Patron

Hey @VernYerem,

 

No need to create a new relationship here, use the Requested Item > Requested For from the available list.

JamesChun_0-1709686644697.png

 

Cheers

Ah! Best answer, it's already there and I was searching for the incorrect terms. Thanks @James Chun 

Sumanth16
Kilo Patron

Hi @VernYerem ,

 

ou can use "Defined Related List" for your requirement. You can follow below steps

Goto System Definition > Relationships

Click New

Set valid name for your related list

Set Applies to table as sc_request table

Set Queries from table as sys_user table

Use the below code in "Query with"

var group = [];
var grTask = new GlideRecord("sc_task");
grTask.addQuery("request_item",parent.sys_id);
grTask.query();
while(grTask.next()){
  group.push(grTask.assignment_group.sys_id.toString());
}

var users = [];
var grUser = new GlideRecord("sys_user_grmember");
grUser.addEncodedQuery("groupIN" + group.join(","));
grUser.query();
while(grUser.next()){
  users.push(grUser.user.sys_id.toString());
}
current.addEncodedQuery("sys_idIN"+users.join(","));

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda