- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2022 07:44 AM
Hi All,
I request you , please help me on below issue.
"cmdb_ci_service_discovered" table record has 'Corporation' field which referencing "u_corporation" table
Request : Corporation record has "Node" reference field which is referencing same table of record itself .
Here Hierarchy: CMDB ServiceDiscovered has "corporation" field which referencing "Test 2" ----> Test 2 record of Node field Referencing "Test 3", Test 3 record of Node field Referencing "Test 4".......etc..
So now we need to check till which corporation record of Node field is empty . so that record display need to Display in CMDB ServiceDiscovered.
i tried below code , but not working
var corSYSID ='';
var bs = new GlideRecord('cmdb_ci_service_discovered');
bs.addQuery('sys_id','04398b559f030200fe2ab0aec32e70fa');
bs.addQuery('u_corporationISNOTEMPTY');
bs.query();
if (bs.next())
{
gs.print('Gate 1 :' + bs.u_corporation.getDisplayValue());
var cor = new GlideRecord('u_corporation');
cor.addQuery('u_nodeISNOTEMPTY');
cor.addQuery('sys_id', bs.u_corporation);
cor.query();
if (cor.next())
{
gs.print('Gate 2 :' + cor.u_node.getDisplayValue());
corSYSID = cor.u_node;
for (var i = 0; i < repeat; i++)
{
var cor2 = new GlideRecord('u_corporation');
cor2 .addQuery('u_nodeISNOTEMPTY');
cor2 .addquery('u_node', corSYSID);
cor2 .query();
if(cor2 .next())
{
repeat ++;
corSYSID = cor2.u_node;
gs.print('Gate 3 :' + cor2 .u_node.getDisplayValue() + '--' + repeat);
}
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2022 10:57 AM
var corSYSID = '',
repeat = 0;
var bs = new GlideRecord('cmdb_ci_service_discovered');
bs.addQuery('sys_id', '04398b559f030200fe2ab0aec32e70fa');
bs.addQuery('u_corporationISNOTEMPTY');
bs.query();
if (bs.next()) {
corSYSID = bs.getValue("u_corporation");
gs.print('Gate 1 :' + bs.getDisplayValue("u_corporation"));
var cor = new GlideRecord('u_corporation');
cor.addQuery('u_nodeISNOTEMPTY');
cor.addQuery('sys_id', corSYSID);
cor.query();
if (cor.next()) {
gs.print('Gate 2 :' + cor.getDisplayValue("u_node"));
corSYSID = cor.getValue("u_node");
while (corSYSID != "") {
var cor2 = new GlideRecord('u_corporation');
cor2.addQuery('u_nodeISNOTEMPTY');
cor2.addQuery('sys_id', corSYSID);
cor2.query();
if (cor2.next()) {
corSYSID = cor2.getValue("u_node");
gs.print('Gate 3 :' + cor2.getDisplayValue("u_node") + '--' + (repeat++));
if (repeat >= 20) break; // You may want to remove this line later after your test is successful.
} else {
// Corporation with empty node
break;
}
}
}
}
Thanks for clarification!
Please try this.
In the code "addquery" was used instead of "addQuery", system might be ignoring that part of query and may be always landing at same node.
Thanks and regards,
Subrahmanyam Satti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2022 08:09 AM
Hi Sironi,
If you are trying to fetch display value or value of a field on the GlideRecord then you have to pass field as parameter to getDisplayValue() or getValue() method.
And when you are using dot walking you have to use getDisplayValue() and getValue().
i.e. bs.getDisplayValue("<field_name>")
And if the field is on reference table of the table you are querying you have to use as below:
bs.<field_name>.<field_name>.getDisplayValue();
Try below code and check!
var corSYSID = '',
repeat = 0;
var bs = new GlideRecord('cmdb_ci_service_discovered');
bs.addQuery('sys_id', '04398b559f030200fe2ab0aec32e70fa');
bs.addQuery('u_corporationISNOTEMPTY');
bs.query();
if (bs.next()) {
gs.print('Gate 1 :' + bs.getDisplayValue("u_corporation"));
var cor = new GlideRecord('u_corporation');
cor.addQuery('u_nodeISNOTEMPTY');
cor.addQuery('sys_id', bs.getValue("u_corporation"));
cor.query();
if (cor.next()) {
gs.print('Gate 2 :' + cor.getDisplayValue("u_node"));
corSYSID = cor.getValue("u_node");
while (corSYSID != "") {
var cor2 = new GlideRecord('u_corporation');
cor2.addQuery('u_nodeISNOTEMPTY');
cor2.addquery('u_node', corSYSID);
cor2.query();
if (cor2.next()) {
repeat++;
corSYSID = cor2.getValue("u_node");
gs.print('Gate 3 :' + cor2.getDisplayValue("u_node") + '--' + repeat);
} else {
break;
}
}
}
}
Thanks and regards,
Subrahmanyam Satti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2022 08:13 AM
Hi Subrahmanyam,
is FOR-LOOP declaration correct ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2022 08:20 AM
I modified for loop to while just now in above reply.
For was looping indefinitely.
Please check code given by me again and try.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2022 08:36 AM
Hi,
Not sure what was the error, Code not working, after running code screen was freeze .
i am assuming that some modification might be required in this point
corSYSID = cor.getValue("u_node");
while (corSYSID != "") {
var cor2 = new GlideRecord('u_corporation');
cor2.addQuery('u_nodeISNOTEMPTY');
cor2.addquery('u_node', corSYSID);
cor2.query();
if (cor2.next()) {
repeat++;
corSYSID = cor2.getValue("u_node");
gs.info('Gate 3 :' + cor2.getDisplayValue("u_node") + '--' + repeat);
} else {
break;
}
}