- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2020 10:19 AM
Hi everyone,
I have this Transformmap to map departments into the ootb table cmn_department.
I want to achieve that during import, the target field "id" will filled with leading zeros -> field "string length < 4". I.e. "2" becomes "0002" or "100" becomes "0100".
Thanks for your help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2020 11:25 AM
Sorry, now better got your requirement. Try this one:
answer = (function transformEntry(source) {
var length = source.u_id.toString().length;
if(length>4) return source.u_id.substring(0,4); //ensure the field is 4-character length
else if(length == 3) return '0' + source.u_id;
else if(length == 2) return '00' + source.u_id;
else if(length == 1) return '000' + source.u_id;
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2020 10:36 AM
Use a following source script for mapping target 'id' field:
answer = (function transformEntry(source) {
return '000' + source.u_id; // return the value to be put into the target field
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2020 10:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2020 11:25 AM
Sorry, now better got your requirement. Try this one:
answer = (function transformEntry(source) {
var length = source.u_id.toString().length;
if(length>4) return source.u_id.substring(0,4); //ensure the field is 4-character length
else if(length == 3) return '0' + source.u_id;
else if(length == 2) return '00' + source.u_id;
else if(length == 1) return '000' + source.u_id;
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2020 12:18 AM