String field is taking values after dot in a integer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2023 05:28 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2023 05:33 AM
Use parseInt method to get integer value as below
var testStr = '3456.09';
var testStr2 =parseInt(testStr);//value will be 3456
Thanks,
Manjusha Bangale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2023 05:37 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2023 05:52 AM
@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.
Thanks & Regards,
Vasanth