OL Learn

Print Shop designer VD Random

Hi I have a job where I have 12 song titles on an A6 card but each card cant have the same sequence of song titles on it so each card is unique.

I have been given an excel doc with 12 columns of random numbers from 1 to 22.

I have 22 song titles ie U2 That I need to associate with say number 1 so that whenever number 1 comes round in the data that is the song title it will put in.

I have tried making number 1 CONDITIONAL U2 but this doesn’t work?

All the random number data and the song titles are in the same excel doc in different columns.

Im thinking its because the excel doc needs to be set up differently in order for me to populate the info?

Any help would be appreciated.

David Perrett

You could format your Excel sheet like this:

s1,s2,s3,s4,s5,s6,s7,s8,s9,songs
8,4,7,9,2,5,1,3,6,"song1,song2,song3,song4,song5,song6,song7,song8,song9"...

In this example, the first line is just the column headers. On the second line, the first 9 fields are the random ordered song indexes. The last field is named “songs” and contains a list of comma-separated song titles (which is why the entire list is enclosed inside double-quotes).

In your template, you use a script to store all the song titles found in the “songs” field in an array:

var allSongs = record.fields[“songs”].split(",");

Then, for each of the s1 … s9 fields, which contain random ordered indexes, you create a script similar to this:

var result = allSongs[parseInt(record.fields[“s1”])-1];
results.html(result);

So the code above reads the random value in field s1 (i.e. “8”), and uses it (after subtracting one from the value because array indexes start at 0) to find the song name inside the array you provided in the previous step, which in this case would yield “song8”.