Unable to dot walk in sys_relationship ( Related List ) from task table query

Sourabh Deshpa1
Giga Contributor

Hello fellow NOWers,

 

I am stuck in a point where I have a workaround but wanted to try if somebody has an answer for this.

Ask is to show a Task related list under User record to list the Incidents and RITMs raised by him ONLY.

However, OOB relationship building would not let us achieve this since, caller_id ( of Incident ) and Requested_for ( of RITM ) are not inherited from Task table.

Hence, 

Applies to : User

Query from : Task

current.addQuery('incident.caller_id',parent.sys_id).addOrCondition('request.requested_item.requested_for',parent.sys_id);  - will not work nor will the below,

current.addQuery('caller_id',parent.sys_id).addOrCondition('requested_for',parent.sys_id);  

Workaround is to create two separate related lists ( infact, they already exist ) and use Default filter for any kind of modifications.

Help me with anything more insightful on this.

Thanks in advance.

4 REPLIES 4

Dubz
Mega Sage

I think you have two options here, you could either leverage the OOB related list for task.opened_by to show all task records opened by the current user OR you could create two separate relationships, one between user and incident and one between user and request_item.

I think either option would work and would be preferable to a single list of incidents and request items which would just look messy tbh. 

The best option in my mind would be to just create a module showing a list of the records you want but if the requirement is specifically for a related list then use one of these options.

Hello David,

Unfortunately as I have mentioned, the fields ( coloumns ) we are referring to, are caller ( in INC ) and Requested for ( in RITM ) . Thus, cannot use opened_by for the same.

Also, the sys_relationship builder available does not let us dot walk as I mentioned in script above.

 

Should I safely say creating 2 separate related lists would be the ideal workaround?

I think that's your only option. To be honest, i think it makes more sense having two separate relationships for those anyway, there are different fields you would want to have on the list view anyway.

Sourabh Deshpa1
Giga Contributor

I could finally achieve it by encoding my query as suggested in one of the other articles. 

var callerID = parent.sys_id;

if (JSUtil.notNil(callerID)) {
var inc = "sys_class_name=incident^ref_incident.caller_id=" + callerID;
var rtm = "sys_class_name=sc_req_item^ref_sc_req_item.request.requested_for=" + callerID;
current.addEncodedQuery(inc + "^NQ" + rtm + "^ORDERBYDESCsys_created_on");
} else
current.addEncodedQuery("sys_idISEMPTY");