how to get the value of a reference field which refers its table itself

Alextia
Giga Expert

Hi,

Actually I can't  get the value of a reference field (which refers its table itself )using Glide Record in Script include.

Is it because of same table itself added as reference field?

Ex.

Table1

name   parent(reference field ->Table1.name)

John  

Sam      John 

Mike   John

So, if I want to know the parent of mike, I suppose to use  Table1.parent.name but its not working.

can anyone let me know how we can handle this scenario?

 

Thanks

 

 

1 ACCEPTED SOLUTION

@Alextia ,

 

Filter Navigator -> system logs -> All

 

PRINCE_ARORA_0-1678439496686.png

 

 

Also in my previous reply I have mentioned pls try a small script in background script to get confirmation whether its working or not!

var gr = new GlideRecord("sys_user");

gr,get("SYS_ID_OF_USER");

gs.info(gr.YOUR_FIELD_NAME.name);

 

Also In your script can you try this : (I am assuming you are implementing reference qualifier on reference field of user table)

var tax_node = new GlideRecord('spm_taxonomy_node');
var tech_srv = tax_node.addJoinQuery('cmdb_ci_service_technical','name','spm_taxonomy_node.name'); tech_srv.addCondition('u_ci_id',current.variables.app_name_with_cmdb.u_ci_id);
tax_node.query();

gs.info("getRowCount() " + tax_node.getRowCount() );// add this for debugging purpose
if (tax_node.next()){
s += tax_node.parent+ ',';
}
return 'sys_idIN' + s;


 If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

View solution in original post

7 REPLIES 7

-O-
Kilo Patron
Kilo Patron

Probably something wrong with your code, cause the scenario is valid.

So share your code so people can debug ti.

Prince Arora
Tera Sage
Tera Sage

@Alextia ,

 

This scenario is completely valid, as you can see in the incident table we have a parent incident field which refers to incident table itself, only thing which you have missed is when you create the field please perform this configurations

 

PRINCE_ARORA_0-1678383872332.png

 

PRINCE_ARORA_1-1678383900746.png

 

This will work 100%

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Hi,

Thank you for the reply

I tried with above settings but still its not returning the value.

here is my code:

var tax_node = new GlideRecord('spm_taxonomy_node');
var tech_srv = tax_node.addJoinQuery('cmdb_ci_service_technical','name','spm_taxonomy_node.name'); tech_srv.addCondition('u_ci_id',current.variables.app_name_with_cmdb.u_ci_id);
tax_node.query();
if (tax_node.next()){
s += tax_node.parent.name + ',';
}
return 'nameIN' + s;

@Alextia ,

 

I have tried the same scenario in my PDI and I was not able to access the reference field before the configurations and after making these changes user was accessible for me. For the confirmation you can try below script in background script like you will get Idea whether it is working or not

 

var gr = new GlideRecord("sys_user");

gr,get("SYS_ID_OF_USER");

gs.info(gr.YOUR_FIELD_NAME.name);

Now  if we talking about your script, I am not aware of the business logic of your scenario, but yes for debugging purpose, can you add gr.getRowCount() in the script just got to know whether you receive any information after applying the filter.

 

var tax_node = new GlideRecord('spm_taxonomy_node');
var tech_srv = tax_node.addJoinQuery('cmdb_ci_service_technical','name','spm_taxonomy_node.name'); tech_srv.addCondition('u_ci_id',current.variables.app_name_with_cmdb.u_ci_id);
tax_node.query();

gs.info("getRowCount() " + tax_node.getRowCount() );// add this for debugging purpose
if (tax_node.next()){
s += tax_node.parent.name + ',';
}
return 'nameIN' + s;

if the above log is returning 0 as output, please check you applied filters their might be some issues in that.

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.