Page 1 of 1

Selecting a specified amount of chars form a field

Posted: Tue Dec 10, 2013 2:56 pm
by Wayne C.
I'm trying to retrieve and display images on a screen in Genie. I'm already doing this on one screen using the following instruction.
script: '/profoundui/userdata/images/ttg/trailers/' + get('D_2_9') +'-d' + '.jpg'

This works because Im using the entire value of D_2_9 . I have another file to display images. I have groups of items (t-shirts) that have the exact same part # plus an additional suffix (t-shirt size). an example below.
XXXXXXXXX - S
XXXXXXXXX - XS
XXXXXXXXX - LG
XXXXXXXXX - XLG
The image for these 4 part #s are the same. We don't want to store 4 duplicate images. Is there a way to modify a script similar to the one above to only use the first 9 characters of this part # to retrieve an image?

Thanks in advance.

Re: Selecting a specified amount of chars form a field

Posted: Tue Dec 10, 2013 4:25 pm
by Scott Klement
The code is JavaScript, so you can code just about anything you can imagine...

Maybe do something like this? (assuming the XXXXXXXXX is always exactly 9 characters long)

Code: Select all

script: '/profoundui/userdata/images/ttg/trailers/' + get('D_2_9').substring(0,9) +'-d.jpg'

Re: Selecting a specified amount of chars form a field

Posted: Wed Dec 11, 2013 1:18 pm
by Wayne C.
Thanks Scott for your help. That worked great. It's a great addition to my limited javascript toolbox. However, turns out that the manufacturer's code won't always be 9 so we are going to have to rethink this. We may have to store duplicate images to keep things consistent with all the manufacturers we deal with.

Thanks again!

Re: Selecting a specified amount of chars form a field

Posted: Wed Dec 11, 2013 5:14 pm
by Scott Klement
Another way to deal with it (slightly more complicated) is to search for the dash. Since all of your examples have "XXXXXX - YYY", there's always a dash after the number and before the size. So you could write code that searches for the dash and strips everything after it. Then the length of the XXXXX wouldn't matter.

Would that be of interest to you?

Re: Selecting a specified amount of chars form a field

Posted: Wed Dec 11, 2013 5:22 pm
by Scott Klement
Maybe even easier... just take everything before the first blank in the string

Code: Select all

script: '/profoundui/userdata/images/ttg/trailers/' + get('D_2_9').split(" ", 1) +'-d.jpg'