"addQuery" or "IF" condition to check whether "TABLE_A.FIELD_A.sys_id = TABLE_B.FIELD_B.sys_id" or not.

Aki17
Kilo Guru

I would like to compare the sys_id of 2 fields of different table for each.

Could someone please tell me how to describe "addQuery" or "IF" condition to check whether "TABLE_A.FIELD_A.sys_id = TABLE_B.FIELD_B.sys_id" or not?

Best Regards,

Aki

5 REPLIES 5

Abhijit4
Mega Sage

Hi Aki,

You don't need to dot walk to get sys_id, reference field by default returns sys_id. However, many of us are not aware that we could use dot walking in encoded query itself as shown below( at line change.addEncodedQuery("problem.category="+incident.problem.category)) example.

I hope this example would help you to compare reference dot walking fields in more efficient way.

This example finds out incident and change records which are having associated problem records with same category.

var incident=new GlideRecord("incident");
incident.addEncodedQuery("active=true");
incident.query();
while(incident.query()){
var change=new GlideRecord("change");
change.addEncodedQuery("problem.category="+incident.problem.category);
change.query();
while(change.next(){
gs.print("This incident and change are having same problem category : Incident:"+incident.number+" Change :"+change.number);
}
}

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP