Relationship creation in HR case table

anilkumarsharma
Giga Guru

Good evening, Team,

This is oob code which is wrote in related list (Cases Opened for User ).

i am not able to understand the line ( gr.addQuery('sys_id',"!=", parent.sys_id);) because when i open the hr record in hr case table and open the same record in task table where sys id of the record is same.

 

is parent refering to task table? Please guide me if i am wrong.

 

anilkumarsharma_0-1674216717645.png

 

 

 

2 REPLIES 2

-Andrew-
Kilo Sage

Hi, 

In this case, it is likely that the parent variable refers to the HR case table, as you mentioned.
The line of code gr.addQuery('sys_id',"!=", parent.sys_id); is used to exclude the current record from the list of related records displayed on the "Cases opened for user" related list.

In the context of the "Cases opened for user" related list, the gr variable is a GlideRecord object that is used to query the task table. The addQuery method is used to add a query to the GlideRecord object, in this case, it's querying the sys_id field for records that are not equal to the sys_id of the parent record. The parent variable is an object that represents the current record being viewed. So, if the user is viewing a HR case record in the HR case table, the parent variable will hold the sys_id of that record.

This line of code is used to exclude the current record from the list of related records displayed on the "Cases opened for user" related list. This is because the current record is already displayed on the form and it is not necessary to include it again on the related list.

This line of code can be seen as a filter to filter out the current record from the list of related records, it makes sure that the current record is not displayed in the related list of cases opened for user.


Hi Sir

below line is not clear. for example. when we open the 

this case, it's querying the sys_id field for records that are not equal to the sys_id of the parent record

for example. when we open below mention record have the sys_id is a619f77f0b2022003be12da0d5673a03 and same sys_id is there in task table then how gr.addQuery('sys_id',"!=", parent.sys_id); condition will true. Please explain me 

 

var gr = new GlideRecord('sn_hr_core_case');
var qc = gr.addQuery("opened_for", parent.opened_for);
qc.addOrCondition("subject_person", parent.opened_for);
gr.addQuery('sys_id',"!=", parent.sys_id);

 

anilkumarsharma_0-1674223313926.png