Parent and child lookup in CI relationship table is giving undefined value through transform map

ashimagupta
Tera Contributor

Hi Team,

I am working on CMDB project where I am importing CI relationship from staging to target table. I have put parent and child as coalesce true so that if there is existing parent and child relationship then it will either update the relationship type or ignore it based on information we get. But it seems coalesce is not working in this case. Relationship record is inserted everytime when I push data from staging to target table. (data is imported through scheduled jobs)

I Observed like when I try to lookup for parent and child, it gives me all records whose name starts with CI name which I am sending for lookup.

To avoid this issue. I wrote source script for parent and child where I am gliding cmdb_ci table to get sysid of particluar record. but here what is new issue i am getting that transform map is unable to do lookup on sysid which I am passing through source script and inserting new records everytime with value "empty" in both child and parent.

Could you please assist how can I uniquely do lookup for parent and child field from cmdb_ci table for CI relationship table

 

Below is source script code for both parent and child

 

Child :

answer = (function transformEntry(source) {

var ch = new GlideRecord('cmdb_ci');
ch.addQuery('name', source.u_child_ci);
ch.addQuery('sys_class_name', 'cmdb_ci_storage_volume'); // this query i added just to get record from storage volume class
ch.query();
if(ch.next())
{
answer = ch.sys_id; 
gs.log("child sysid" + answer);
}
else
{
answer = -1;
}
})(source);

 

Parent :

 

answer = (function transformEntry(source) {

var pa = new GlideRecord('cmdb_ci');
pa.addQuery('name', source.u_parent_ci);
pa.addQuery('sys_class_name', 'cmdb_ci_storage_server');
pa.query();
if(pa.next())
{
answer = pa.sys_id; // return the value sysid to be put into the target field
gs.log("parent sysid with child and relation" + answer +'<<>>' + source.u_child_ci + '<<>>'+source.u_relationship_type);
}
else
{
answer = -1;
}
})(source);

 

Really appreciated your quick assistance. Attached screenshot

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,


Can you please update the is loop as below:

if(ch.next())
{
return ch.sys_id; 
gs.log("child sysid" + answer);
}
else
{
return -1;
}

 

Which means answer = -1 or answer = sys_id, 

 

Thanks,
Ashutosh Munot

View solution in original post

1 REPLY 1

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,


Can you please update the is loop as below:

if(ch.next())
{
return ch.sys_id; 
gs.log("child sysid" + answer);
}
else
{
return -1;
}

 

Which means answer = -1 or answer = sys_id, 

 

Thanks,
Ashutosh Munot