How to eliminate dot walking

Sachin G K1
Kilo Sage

Hi Everyone,

i want to eliminate dot walking which i have highlighted in bold. How to do that, please suggest.

 

 

Script include function:

 

getAllrelated: function(ci_sysID) {
this._j = this._j + 1;
if (this.RelatedCI.join(',').indexOf(ci_sysID) != -1 || this._j == 500) {
return this.RelatedCI;
}

else {
this.RelatedCI.push(ci_sysID);
}
var gr = new GlideRecord("cmdb_rel_ci");
gr.addQuery("parent", ci_sysID); //get all the children for the given CI
gr.addQuery('child.sys_class_name', '!=', 'cmdb_ci_cluster');
gr.query();
while (gr.next()) {
var child_sysID = gr.child.sys_id;
this.getAllrelated(child_sysID);
}
return this.RelatedCI;
},

 

Thanks in Advance,

Sachin

1 ACCEPTED SOLUTION

AnubhavRitolia
Mega Sage
Mega Sage

Hi Sachin,

 

Firstly, this level of dot Walking is not an issue and you can use it.

 

Still if you want to eliminate it, you have to again GlideRecord your Child Table (I Guess it will be 'cmdb_ci') and filter using sys_id as gr.child.

 

while (gr.next()) {
var child_sysID = gr.child.sys_id;
this.getAllrelated(child_sysID);
}

Replace above code as below:

while (gr.next()) {

var child = new GlideRecord('cmdb_ci');
child.addQuery('sys_id',gr.child);
child.query();
if(child.next())
{
var child_sysID = child.sys_id;
}
this.getAllrelated(child_sysID);
}

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

2 REPLIES 2

AnubhavRitolia
Mega Sage
Mega Sage

Hi Sachin,

 

Firstly, this level of dot Walking is not an issue and you can use it.

 

Still if you want to eliminate it, you have to again GlideRecord your Child Table (I Guess it will be 'cmdb_ci') and filter using sys_id as gr.child.

 

while (gr.next()) {
var child_sysID = gr.child.sys_id;
this.getAllrelated(child_sysID);
}

Replace above code as below:

while (gr.next()) {

var child = new GlideRecord('cmdb_ci');
child.addQuery('sys_id',gr.child);
child.query();
if(child.next())
{
var child_sysID = child.sys_id;
}
this.getAllrelated(child_sysID);
}

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Wouldn't it make more sense to store it as this: 

var child_sysID = gr.getValue('child') +'';

Instead of :

var child_sysID = gr.child;

 

That way it is not referencing an object. 


Best regards,
Sebastian Laursen