Transform map with distinguishing different CIs with the same name

kszymon89
Tera Contributor

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.

8 REPLIES 8

Hitoshi Ozawa
Giga Sage
Giga Sage

Columns setup in Indentification Rule can be used to identify a CI. Identification rule is setting what ServiceNow will use to determine if the CI already exists in the database.

Common identification are name and serial number.

https://docs.servicenow.com/bundle/sandiego-servicenow-platform/page/product/configuration-managemen...

https://docs.servicenow.com/bundle/sandiego-servicenow-platform/page/product/configuration-managemen...

 

kszymon89
Tera Contributor

Thank you Hitoshi. I'm working on the transform script which could recognize the CI based on the name and Class value provided in data source. I need to import data to the custom table with the reference fields from another tables, like cmdb_ci (which means that cmdb_ci is not a target table).

I've managed to create the script to be able to match the correct CI from cmdb_ci table to compare with what I have in my data source. However, in my second addQuery() for sys_class_name expected value is not for instance "Windows Server", but "cmdb_ci_server". The thing is, that I would like to use the display value from the data source.

answer = (function transformEntry(source) {

	var gr = new GlideRecord('cmdb_ci');
	gr.addQuery('name',source.u_name);
	gr.addQuery('sys_class_name',source.u_class); // This line is wrong...
	gr.query();

	if (gr.next()) {
		
		return gr.sys_id.toString();
			
	}
})(source);

find_real_file.png

In my case I cannot distinguish by any other column, unfortunately and need to specify the condition based on Class field as well along with the name. 

Does anyone of you know how to define addQuery or update my script to be able to take the display values for Class column from my data source and use them in my addQuery condition? Without defining all possible Classes in my code?

Thank you in advance for help!

Ravi9
ServiceNow Employee
ServiceNow Employee

is the "class" column data exactly same as label of the actual table ? if yes  then maybe you can query the sys_db_object with that and get the table name , obviously there could be some risk if labels are duplicate !

emir
ServiceNow Employee
ServiceNow Employee

query cmdb_ci_server if you expect server in the payload, you can go more granular at this step:

var gr = new GlideRecord('cmdb_ci');