String field is taking values after dot in a integer

Suve3
Tera Contributor

Hi All,

 

I have created a string field to get values through transform map. The format will be xxxx.xx i.e, 3456.09 . The string field is taking the whole decimal value and i want only the numbers left to the dot to be displayed. i.e., 3456 in the field. How can we achieve this? Please suggest

3 REPLIES 3

manjusha_
Kilo Sage

@Suve3 

 

Use parseInt method to get integer value as below

var testStr = '3456.09';

var testStr2 =parseInt(testStr);//value will be 3456

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

Thanks,

Manjusha Bangale

Ankur Bawiskar
Tera Patron
Tera Patron

@Suve3 

you can use field map script or transform onBefore script

Field Map script

answer = (function transformEntry(source) {

	// Add your code here
	return parseInt(source.u_importSetField); // give correct import set field name here

})(source);

Transform onBefore script

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

	// Add your code here
	target.fieldName = parseInt(source.u_importSetField); // give correct field names here from target and import set

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Vasantharajan N
Giga Sage
Giga Sage

@Suve3 - 

Please try this below Source script to set the expected value in the target table field

answer = (function transformEntry(source) {

	// Add your code here
	if(!source.u_number.nil()){
		return source.u_number.split(".")[0]; // replace u_number with correct staging table field value
	}
	
	return ""; // return the value to be put into the target field

})(source);

Just for your reference update the highlighted value in your transform map and check.

VasantharajanN_0-1680180677813.png

 

 


Thanks & Regards,
Vasanth