Transform map CMDB Issue

RohitKumar24
Tera Contributor

Hi Community ,

 

I am facing an issue whenever using Transform map to make entries to CMDB, there is a column of 12 digit numeric ID as AWS ID but in the excel sheet my teammate get to import in table . It contains less than 12 digit because the number in starting are 000. For example In sheet I get a AWS ID as 123456789 but when I have to tranform it to CMDB table it should be displayed in AWS ID column as 000123456789 i.e 12 digits fixed always, if less than 12 while transforming I have to make it 12 digits by putting zeroes in front of the number. In some cases I tried to insert 000 (zeroes) in sheet itself before transforming but while transforming the transform map is removing the zeroes in front of the number .

Please help if someone have the knowledge on this .

 

Rohit Pargain 

+918650834395

1 ACCEPTED SOLUTION

You can use a transform script to add chars to the value before using it.

 

Something like this

answer = (function transformEntry(source) {

	var id = source.u_field_name_of_aws_id;
	var failsafe = 0;
	//As long as the id is less than 12 chars long then we add a 0 before
	while(id.length < 12 && failsafe < 10){

		id = '0' + id;
		failsafe++; //prevents infinite look in case something goes wrong - a max of 10 loops
	}
	return id; // return the value to be put into the target field

})(source);

 

SimonChristens_0-1733905562506.png

Then set the target field to the field you want the ID set.

This isnt tested though but hopefully it helps a bit

 

View solution in original post

2 REPLIES 2

RohitKumar24
Tera Contributor

Any help or idea will be beneficial for my learning.

You can use a transform script to add chars to the value before using it.

 

Something like this

answer = (function transformEntry(source) {

	var id = source.u_field_name_of_aws_id;
	var failsafe = 0;
	//As long as the id is less than 12 chars long then we add a 0 before
	while(id.length < 12 && failsafe < 10){

		id = '0' + id;
		failsafe++; //prevents infinite look in case something goes wrong - a max of 10 loops
	}
	return id; // return the value to be put into the target field

})(source);

 

SimonChristens_0-1733905562506.png

Then set the target field to the field you want the ID set.

This isnt tested though but hopefully it helps a bit