Identifying the data source from the transform map

D Dejesus
Tera Contributor

Our goal is to use a single transform map as a central point for multiple data sources to write to for our CMDB, but we have a requirement to also identify on the fly which data source made the call. 


Is there anyway to do this that doesn't involve passing the data through the data source, which we can not do for certain sources? 

1 ACCEPTED SOLUTION

ARG645
Tera Guru

The function getDataSourceName mentioned in the below scripts

Should be used in OnStart Scripts the following way

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// Add your code here
	var dataSourceName= getDataSourceName();
	
	function getDataSourceName() // This function expects atleast one record in the Import set Table
	{
		source.next();
		var dataSourceName = source.sys_import_set.data_source.name;
		source.setLocation(-1);
		return dataSourceName;
	}

})(source, map, log, target);

 

If you want to use it in Onbefore Script, then use it the below way

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// Add your code here
	var dataSourceName= getDataSourceName();
	
	function getDataSourceName() 
	{
		var dataSourceName = source.sys_import_set.data_source.name;
		return dataSourceName;
	}

})(source, map, log, target);

View solution in original post

2 REPLIES 2

ARG645
Tera Guru

The function getDataSourceName mentioned in the below scripts

Should be used in OnStart Scripts the following way

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// Add your code here
	var dataSourceName= getDataSourceName();
	
	function getDataSourceName() // This function expects atleast one record in the Import set Table
	{
		source.next();
		var dataSourceName = source.sys_import_set.data_source.name;
		source.setLocation(-1);
		return dataSourceName;
	}

})(source, map, log, target);

 

If you want to use it in Onbefore Script, then use it the below way

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// Add your code here
	var dataSourceName= getDataSourceName();
	
	function getDataSourceName() 
	{
		var dataSourceName = source.sys_import_set.data_source.name;
		return dataSourceName;
	}

})(source, map, log, target);

D Dejesus
Tera Contributor

Perfect! The solution works great. Note to anyone else who is having trouble, this returns 'undefined' if you do a test load. But load the data properly, and you'll get back the name of the data source!