Can't get slice to work

var OrderNo = varCovArray[6];
var OrderNo6 = varCovArray[6].substr(7,6);

If my order number is 13 characters the above works.

But if my order number is more than 13 characters, it doesn’t. I need to pickup the last 6 characters of the order number for any string length.

So, if my order number is 1105120908528_T2, the result is “528_T2”.
If my order number is 1105120985597, the result is “985597”.

below is what I am working on.

var DataToEncode = $arg1 + "90000";
var isbn10 = ("ISBN-10: " + $arg2.substr(0,1) + "-" + $arg2.substr(1,3) + "-" + $arg2.substr(4,5) + "-" + $arg2.substr(9,1));
var isbn13 = ( "ISBN-13: " + $arg1.substr(0,3) + "-" + $arg1.substr(3,1)  + "-" + $arg1.substr(4,3) + "-" + $arg1.substr(7,5)  + "-" + $arg1.substr(12,1) );
var varCov= $arg3;
var sku = $arg4;
var coverText = $arg5;
var mycovertext = new File(coverText);
var arcPath = "/Volumes/McGraw Hold/" + $arg4 + "/" + $arg4 + ".indd";
var arcPathpkg = "/Volumes/McGraw Hold/" + $arg4 + "/Source/" ;

var varCovArray = varCov.split("-");
var varCovSwitch = varCovArray[0];
var spine = varCovArray[1]
var volNum = varCovArray[2];
var jobQtyDisplay = varCovArray[3]
var jobQty= parseInt(varCovArray[3]);
var LocCode = varCovArray[4];
var AccessCodes_BkCvrCount = varCovArray[5];
var OrderNo = varCovArray[6];
//var OrderNo6 = varCovArray[6].substr(7,6);
var OrderNo6 = varCovArray[6].slice(-6);

String.substr(start,count)
If start is a negative number, the function counts from the end of the string and count is an optional argument

1 Like

I see what my partner did here, she was trying to “subtract” rather implementing the position. I’ll fix it up and let you all know how it goes.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.