Query on Relationship

devservicenow k
Tera Contributor

Requirement is to Display all the Emails From Incident and Case table to display in the Related list of Case Record.

So i have created a Relationship in case table.

 

But i am Not able to get the Correct Output, do i need to add any additional query

help me with script .

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage
Mega Sage

If you are looking for all emails on the incident and case table, then use below statement.

current.addQuery('target_table', parent.sys_class_name).addOrCondition('target_table', 'incident');

 

If you are looking for emails only on current record, then use below statement.

current.addQuery('instance', parent.sys_id);

 

If you are looking for emails on current record along with the emails on incident table, then use below statement.

current.addQuery('instance', parent.sys_id).addOrCondition('target_table', 'incident');

View solution in original post

3 REPLIES 3

Pavankumar_1
Mega Patron

Hi @devservicenow k ,

Try below query.

current.addQuery("target_table", parent.sys_class_name);
current.addQuery("instance", parent.sys_id);
If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Muhammad Khan
Mega Sage
Mega Sage

If you are looking for all emails on the incident and case table, then use below statement.

current.addQuery('target_table', parent.sys_class_name).addOrCondition('target_table', 'incident');

 

If you are looking for emails only on current record, then use below statement.

current.addQuery('instance', parent.sys_id);

 

If you are looking for emails on current record along with the emails on incident table, then use below statement.

current.addQuery('instance', parent.sys_id).addOrCondition('target_table', 'incident');

Anil Lande
Kilo Patron

Hi,

Which field on Case refer to incident?

Do you want all emails related with incidents (All) or any particular incident which is related with Case?

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande