Qlingo/uPlan Programming Help

399 views
Skip to first unread message

Naomi R

unread,
Nov 17, 2017, 11:54:35 AM11/17/17
to XMPie Interest Group

I am in the middle of a project to create a scanline that includes taking an ADOR and converting any letters to numbers, assigning those numbers a weight of 2 or 1, adding together any resulting double digits, dividing that number by 10 then subtracting any decimal from 10 to create a Check Digit.

 

I know there is a way to use a Check Digit function along with a barcode, but our client doesn’t want a barcode on the product. 

Example: The first hurdle is turning AHOMR150101M1234TA7 to 18691501014123431 by replacing all letters with a number value as per the below chart. Is it even possible to change individual parts within an ADOR?

Alpha Conversion
1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
I 9
J 1
K 2
L 3
M 4
N 5
O 6
P 7
Q 8
R 9
S 2
T 3
U 4
V 5
W 6
X 7
Y 8
Z 9

rhopfner

unread,
Nov 17, 2017, 12:15:26 PM11/17/17
to xmpie...@googlegroups.com
My first option would be to ask a data person to create that value on the data side,  but if I had to do it myself I would start with your code, assign it to a new ador with a huge nested find and replace to get your string of numbers, then in another ador select each digit, I can't think of the along function for that, adding those selections and then finishing off your math. Messy, I guess but should work.



Sent from my Sprint Samsung Galaxy S8+.
--
You received this message because you are subscribed to the Google Groups "XMPie Interest Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xmpie-users...@googlegroups.com.
To post to this group, send email to xmpie...@googlegroups.com.
Visit this group at https://groups.google.com/group/xmpie-users.
For more options, visit https://groups.google.com/d/optout.

Iain Dwyer

unread,
Nov 17, 2017, 12:19:06 PM11/17/17
to XMPie Interest Group
I expect you could build a javascript function that does this. split() will break the string into individual characters, from there it would be a matter of looping through each letter and replacing them. You may also be able to build a function that gets passed into the JS replace function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

I don't know of any way to do it with QLingo.
Message has been deleted

Wayne

unread,
Nov 17, 2017, 11:28:58 PM11/17/17
to XMPie Interest Group
To perform the first alpha conversion, using the JavaScript Map function would be the easiest without having to write too much code.
Set the output type=string of the function in uPlan to ensure the output is correct.

function letterValue(str){
    var anum={
        A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8, I: 9, J: 1, K: 2, 
        L: 3, M: 4, N: 5,O: 6, P: 7, Q: 8, R: 9, S: 1, T: 2, 
        U: 3, V: 4, W: 5, X: 6, Y: 7, Z: 8
    }
    return anum[str] || str;
    var arr = str.split('').map(letterValue);
    var s = ''; 
    for (var i = 0, len = arr.length; i < len; i++) {
       s=s+arr[i];
    }
    return s;
}


if you want to get the Checkdigit then this function should do it assuming 0 is the checkdigit if 10 is returned.

 function getScanlineCheckDigit (str) 
var anum={
        A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8, I: 9, J: 1, K: 2, 
        L: 3, M: 4, N: 5,O: 6, P: 7, Q: 8, R: 9, S: 1, T: 2, 
        U: 3, V: 4, W: 5, X: 6, Y: 7, Z: 8
    }
    if(str.length== 1) return anum[str] || str;
    var arr = str.split('').map(getScanlineCheckDigit);
    var s = ''; 
    var w = 2;
    var s2 = ''
    for (var i = 0, len = arr.length; i < len; i++) {
       s=s+arr[i];
       s2=s2+(arr[i]* w)
       w=w-1;        
       if(w==0){w=2; }       
    }
    var s3 = 0;
    var arr2 = s2.split('');
    var total=0;
    for(var i in arr2) { total += parseInt(arr2[i]); }    
    s3 = 10 - (total % 10);
    if(s3 == 10) {s3=0;}
    return s3;


Regards,
Wayne

Naomi R

unread,
Nov 20, 2017, 12:22:18 PM11/20/17
to XMPie Interest Group
Wayne,

Thank you SO much for your help on this! Is there a place in here that I should be referencing the ador? I usually work in Indesign with the plugin and straight coding in uPlan has been a huge leap for me. I'm not sure how to 'apply' this code to the correct field.

Wayne

unread,
Nov 20, 2017, 3:36:41 PM11/20/17
to XMPie Interest Group

Naomi R

unread,
Nov 27, 2017, 5:30:07 PM11/27/17
to XMPie Interest Group
I was able to figure out how to write the Qlingo to replace the letters in my string with numbers. I'm stuck on how to assign weights to each number. The need is for each number in an 18 digit string to be assigned a 2 or 1 from right to left. So character 18 would be multiplied by 2, character 17 would be multiplied by 1, character 16 by 2 etc etc.

Mark Kuehn

unread,
Nov 27, 2017, 5:58:08 PM11/27/17
to xmpie...@googlegroups.com

Yes, to can absolutely change part of an ADOR. You can do this in QLingo, but it will be a long, long, long, expression. This is probably best done with a JavaScript function, but only if you have a uProduce instance.

 

Otherwise you’ll need to preprocess the data with Excel or some other piece of code to get the field “appended” into each data record.

 

From: <xmpie...@googlegroups.com> on behalf of Naomi R <naomiren...@gmail.com>


Reply-To: <xmpie...@googlegroups.com>
Date: Monday, November 27, 2017 at 4:30 PM
To: XMPie Interest Group <xmpie...@googlegroups.com>

--

Reply all
Reply to author
Forward
0 new messages