- 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-17-2020 01:02 AM
Hi,
you will have to do this dynamically in the transform map script or field map script where you are mapping
answer = (function transformEntry(source) {
var incomingId = source.u_id; // your import set field
if(incomingId.length < 4){
if(incomingId.length == 1){
return '000' + source.u_id;
}
if(incomingId.length == 2){
return '00' + source.u_id;
}
if(incomingId.length == 3){
return '0' + source.u_id;
}
}
else{
return incomingId;
}
})(source);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader