Flow designer requirement

Rakshanda Kunte
Tera Contributor

Hi All,

Flow designer requirement:

 

I need to get the department names and numbers by dot walking 2 tables (i.e. Department and Rel). 

I have around 521 entries of department with level4.

 

Department - OOTB Table

Rel - custom table

Level 4 - Reference field in rel table (referencing 'department' table)

 

Dot Walking path as below

Department - rel - level 4 (field on rel table)

 

 

 

I have below script but not working;

var gr = new GlideRecord ('department');
gr.query();
var groupData ={};
while (gr.next())
{
var array = gr.u_rel.u_level_4.name;
if (!groupData[array]){
groupData[array]=[];
}
}
for (var key in groupData){
gs.print ('Family' + ' ' + key);

}

return groupData;

 

Kindly, help with script which runs in flow designer.

3 REPLIES 3

-O-
Kilo Patron
Kilo Patron

The eternal beginner error: adding references to the same object instead of values.

 

gr.<field name>
gr.<reference>...<reference>.<field name>

 

are NOT values from the DB, but objects (GlideElements) (that can retrieve the values from the currently loaded record.

This retrieval happens only when one executes the GlideElement's toString() method, or the (host) GlideRecord's getValue() method.

So statement

 

var array = gr.u_rel.u_level_4.name;

 

should be instead any one of:

 

var array = gr.getValue('u_rel.u_level_4.name');
var array = String(gr.u_rel.u_level_4.name);
var array = gr.u_rel.u_level_4.name.toString();
var array = gr.u_rel.u_level_4.name + '';
var array = '' + gr.u_rel.u_level_4.name;

 

 

Some advice - if you don't mind:

- use proper variable names; array is misleading and confusing - name would be much better.

- try using getDisplayValue(), vs. accessing a field that is currently the display value (in this case name); this might change later, someone might reconfigure the table to use a different field as display value - if that happened you would either have to reprogram your script or your script will be out of sync with the rest of the platform. But if you used the method, all that would no longer be a problem.

E.g:

 

var array = gr.u_rel.u_level_4.getDisplayValue();

 

 

@-O- 

Thanks for your inputs. I will surely look into this.

 

You're welcome.

Also I would appreciate if you liked my answers, or marked the solution in case it helped you in some way or outright solved the problem at hand.