addJoinQuery issue

anilkumarsharma
Giga Guru

Hello Team,

i need to know that how  addJoinQuery work and pass the sys_id.

var thisCI='dfgh1111'// this is CI

 

var grParentCIName = new GlideRecord('cmdb_ci_business_app');
grParentCIName .addEncodedQuery('u_active=true^sys_class_name=cmdb_ci_business_app');
var jq1 = grParentCIName .addJoinQuery('cmdb_rel_ci','sys_id','parent');
jq1.addCondition('child', thisCI);
grParentCI.query();

1 ACCEPTED SOLUTION

raphaelcrv
Kilo Guru

It looks like there are a couple of issues with the provided code. Here's a version of the code with some corrections:

 

var grParentCI = new GlideRecord('cmdb_ci_business_app');
grParentCI.addQuery('u_active', true);
grParentCI.addQuery('sys_class_name', 'cmdb_ci_business_app');
var jq1 = grParentCI.addJoinQuery('cmdb_rel_ci', 'sys_id', 'parent');
jq1.addCondition('child', thisCI);
grParentCI.query();

 

Here are the changes I made:

I removed the extra space between grParentCIName and the . in the first line.
I changed grParentCIName to grParentCI to be consistent with the rest of the code.
I replaced the addEncodedQuery method with addQuery and passed the values as separate arguments. This is a more standard way to add queries to a GlideRecord.
I fixed the typo in the last line where grParentCI was mistakenly referred to as grParentCIName.
These changes should help ensure that the query runs as intended. Note that I assume thisCI is a variable that contains the sys_id of a CI, as it is used in the join condition. If that is not the case, you may need to adjust the code accordingly.

If my response was helpful and/or provided a solution, please consider marking it as such. Thank you!

View solution in original post

5 REPLIES 5

raphaelcrv
Kilo Guru

It looks like there are a couple of issues with the provided code. Here's a version of the code with some corrections:

 

var grParentCI = new GlideRecord('cmdb_ci_business_app');
grParentCI.addQuery('u_active', true);
grParentCI.addQuery('sys_class_name', 'cmdb_ci_business_app');
var jq1 = grParentCI.addJoinQuery('cmdb_rel_ci', 'sys_id', 'parent');
jq1.addCondition('child', thisCI);
grParentCI.query();

 

Here are the changes I made:

I removed the extra space between grParentCIName and the . in the first line.
I changed grParentCIName to grParentCI to be consistent with the rest of the code.
I replaced the addEncodedQuery method with addQuery and passed the values as separate arguments. This is a more standard way to add queries to a GlideRecord.
I fixed the typo in the last line where grParentCI was mistakenly referred to as grParentCIName.
These changes should help ensure that the query runs as intended. Note that I assume thisCI is a variable that contains the sys_id of a CI, as it is used in the join condition. If that is not the case, you may need to adjust the code accordingly.

If my response was helpful and/or provided a solution, please consider marking it as such. Thank you!