Transform map with distinguishing different CIs with the same name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2022 05:51 PM
Hello guys,
I've got some challenging task to import data to the custom table which includes CI name (u_ci) as a reference field (from cmdb_ci table) and some other reference fields like assignment group (taking values from sys_user_group).
I want to import data to this custom table based on existing CIs from the cmdb_ci table, but the thing is that it may happen that in cmdb_ci table there can be more than one CI with the same name, but different sys_id (or Class, or Description). In my source file that I'm going to use for upload I've got both class and description along with the Name and Assignment group, but I don't know how to let the transform map distinguish these different CIs, so they can be inserted or updated as stated in my source file. Every single time I've tried to upload the file, in the best result I've got all the records uploaded with different Assignment groups but only for the same CI (I was using: main script field for the transform map, source script field as a script, onBefore script etc - I've tried to re-use everything I was able to find on the community, but with no succcess)...
Could you please advise what approach should I consider to complete this?
Thank you in advance.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 12:47 AM
The point is, that I've got many records with various classes in my data source and would like to avoid importing them class by class. But, from the other hand, as I mentioned, cmdb table is not the target one, I need to import records to the custom table distinguishing by class from cmdb_ci (and class only).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 09:44 PM
If your source.u_class equals the name of the class, did you try?
sys_class_name.name

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 10:29 PM
i dont know if you seen my response or not but am going to put this here one more time
here is my suggestion
function getClassNameFromLabel(label) {
var q = "label=" + label + "^nameSTARTSWITHcmdb_ci_";
var tble = new GlideRecord("sys_db_object");
tble.addEncodedQuery(q);
tble.query();
tble.next();
return tble.name + "";
}
this will get what you need PROVIDED the query only returns one!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2022 02:09 PM
Hi Ravi and Emir,
Thank you for your replies. I've used something like this in my final code:
answer = (function transformEntry(source) {
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('name',source.u_name);
gr.query();
while (gr.next()) {
if (gr.sys_class_name.getDisplayValue() == source.u_class) {
return gr.sys_id.toString();
}
}
})(source);