Javascript / Transform map scripting help for Apple serial numbers

Jim O_Shea
Tera Expert

Apple adds a nefarious “S” on serial number bar codes attached to their packaging.  Our import process starts at receiving and ends with discovery and have mismatched serial numbers duplicates caused by this.  I’m attempting to add a script to the serial number transform map field, removing the leading “S” from serial numbers during the initial record load. But I’m having issues and would appreciate suggestions….    Thanks, Jim

 

answer = (function transformEntry(source) {
// Add your code here
           var str = u_serial_id;
           var mfc = u_descr254_mixed;
           var newstr = "";
           if (mfc.slice(0,5) == "Apple" && str.slice(0,1) == "S") {
                let newstr = str.slice(1,9);
           } else  {
                let newstr = str;
           }

                return newstr; // return the value to be put into the target field
})(source);

2 ACCEPTED SOLUTIONS

Anand Kumar P
Giga Patron
Giga Patron

Hi @Jim O_Shea ,

Try below script,

answer = (function transformEntry(source) {
var str = source.u_serial_id;
var mfc = source.u_descr254_mixed;
var newstr = "";

if (mfc.slice(0, 5) === "Apple" && str.slice(0, 1) === "S") {
newstr = str.slice(1, 10); 
} else {
newstr = str;
}

return newstr;
})(source);

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

View solution in original post

2 REPLIES 2

Anand Kumar P
Giga Patron
Giga Patron

Hi @Jim O_Shea ,

Try below script,

answer = (function transformEntry(source) {
var str = source.u_serial_id;
var mfc = source.u_descr254_mixed;
var newstr = "";

if (mfc.slice(0, 5) === "Apple" && str.slice(0, 1) === "S") {
newstr = str.slice(1, 10); 
} else {
newstr = str;
}

return newstr;
})(source);

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

Thanks Anand!