- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 03:39 AM
I am bulk uploading relationships to cmdb_rel_ci table using Transform Map, the source table has Child Name, Child Class, Type, Parent Name, Parent Class fields but the target has only Child, Parent and Type fields and there is no direct way to target class of child and parent.
The issue is happening when there are CIs with same but different class of cmdb, so suppose if I want CI name 'ABC' of class 'Application Service' as child but transform is itself picking up CI named 'ABC' of class 'Business Service'.
It seems targeting sys_id is not allowed to script/manually using even admin.
What should be done to solve it ? Any onBefore script can be suggested ?
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 03:47 AM
For each mapping use script instead of field to field mapping
For Parent field
var par = new GlideRecord (source.u_parent_class);
par.get('name', source.u_parent_name);
return par.sys_id;
For Child field
var child = new GlideRecord (source.u_child_class);
child.get('name', source.u_child_name);
return child.sys_id;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 03:47 AM
For each mapping use script instead of field to field mapping
For Parent field
var par = new GlideRecord (source.u_parent_class);
par.get('name', source.u_parent_name);
return par.sys_id;
For Child field
var child = new GlideRecord (source.u_child_class);
child.get('name', source.u_child_name);
return child.sys_id;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 11:20 AM
Genius !
Thank you so much
Please see my reply on other question as well it worked fine on PDI but not where I wanted it to. Must be issue with my roles.
Could you suggest onBefore() script ? Your script work perfectly, just I wanted to know if that way also same result could be achieved.
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 09:26 PM
Hi Ishan,
You can try an onBefore script below. No mapping will be required
var par = new GlideRecord (source.u_parent_class);
par.get('name', source.u_parent_name);
var child = new GlideRecord (source.u_child_class);
child.get('name', source.u_child_name);
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('parent', par.sys_id);
rel.addQuery('child', child.sys_id);
rel.addQuery('type.name', 'Depends on::Used by');
rel.query();
if (!rel.next()){
var relCreate = new GlideRecord('cmdb_rel_ci');
relCreate .initialize();
relCreate.parent = par.sys_id;
relCreate.child = child.sys_id;
relCreate.type = '1a9cb166f1571100a92eb60da2bce5c5';
relCreate.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 03:35 AM
Hi
This also worked in PDI but two additional records were also created.
Note: In future source table could also be having named duplicate where I think I would include more queries to check on other ownership fields as well, your suggestion ?
The structure of CIs is:
Source in Map-> Mapped Application Service(cmdb_ci_service_discovered)
Target-> cmdb_rel_ci
Thanks.