Replicate/Use a JS For Loop in uCreate

252 views
Skip to first unread message

chi...@marketeaminc.com

unread,
Sep 23, 2015, 5:32:36 PM9/23/15
to XMPie Interest Group
As a newbie to XMPie, I need to understand how to replicate the function of a JS For Loop using uCreate Print in InDesign. Additionally, I'd like to collect the various iterations that match specific criteria into an Array for further data manipulation (alphabetize, number, whatever).

I can write the JavaScript, but don't know where/how to insert the code into the rule editor for a Content Object or a Variable. Maybe I can do the work in uPlan? If so, I would need some direction on how to go about that...

I'd appreciate some solid direction and insights.

Thanks,


David Chilton
Mac: OS X (10.8.5)
XMPie uCreate Print 7.1.1 build 8008

couch

unread,
Sep 23, 2015, 6:02:57 PM9/23/15
to XMPie Interest Group
I guess it sort of depends on what you are really trying to do. - EG: You mention alphabetize... What are you alphabetizing? 
If it is the datasource or recipient list, you do that with a filter where you can use standard SQL "order by" syntax.
If it is some other data passed in a field of the database, then, yes, you could use javascript.

You create a javascript function in uplan by defining the type of data it will return, and then adding parameters to it that you will pass to it when you call it.
Double-click the new function and add the javascript code. You can reference the parameters you defined. And, you need to return a value of the type you specified.
To use the function, drag it into a variable or ADOR expression. replace the parameter names with static values, or with other variables or database fields.

I frequently work with comma or pipe separated lists that are passed to a function like this in one data field for each recipient. I use the split() function to create an array and manipulate the data that way.

The thing most "newbies" (as you put it) miss is that uPlan works with only one row of data at a time from the recipient data source. 
IE, read a row, evaluate variables and ADORs, then dump the resolved ADOR values out. Then repeat until the end of the data. 
What I mean is that when evaluating a variable or ADOR, uPlan (and the plan interpreter) is dealing only with one record of data. It does not know what the previous record had, or what the next record will be.

Nick O

unread,
Sep 26, 2015, 2:05:46 AM9/26/15
to XMPie Interest Group
Hey Steve! Out of curiosity has XMPie ever indicated development of, or have you seen an implementation of some method of recipient abstraction? I frequently find myself needing ways to operate on a dataset in parallel as opposed to sequentially. Just curious if anyone else runs into this, and if there is a way to do it.

Thanks,
Nick O

couch

unread,
Sep 26, 2015, 4:58:11 AM9/26/15
to XMPie Interest Group
I'd be interested to hear your use case? - Is it something that you wouldn't be able to do with a userview or query?

Mark Kuehn

unread,
Sep 26, 2015, 9:35:45 AM9/26/15
to xmpie...@googlegroups.com
Nick,

I agree. I have been lobbying for some functional expansion of Qlingo for years. I don't think XMPie will ever switch Qlingo out of its statelessness (too many things would break), but with a few enhancements in limited persistence, a lot of use cases could be solved. My requests were the following:

===

I realize that Qlingo is a stateless language. It could retain this statelessness but with four enhancements the usefulness could be greatly expanded:
  1. Add two special internal states called pre-process and post-process. The purpose of these are to perform special processing via Qlingo.
    • Qlingo in the pre-process state is evaluated immediately after a record is available and before any other variables or ADORs are evaluated
    • Qlingo in the post-process states is evaluated immediate after a record is completely processed (prior to the next record being available)
    • These states are the ONLY situations that the limited persistence is alterable.
  2. Add a Repeat() special function. This function would ONLY be valid within the post-process state. It would cause the current record to be processed again as the "next record", rather than fetching a new record.
  3. Add a single internal Qlingo system "persistent" stored value. This ideally would be a string, but the length of the string could be a fixed length if the developers determine that would simplify implementation.
    • The value of the "persistent data construct" would be returned by the new function PersistentRead(). The PersistenceRead() function could appear in any Qlingo code block.
    • The value of  the "persistent data construct" would be set by the new function PersistentWrite( value ). The PersistenceWrite() function can ONLY appear in pre-process or post-process states.
    • Add a method (via uPlan or uCreate) to set an initial value to the "persistent" stored value.
  4. Add a construct of a saved record. The values of the saved record would be accessed by a new "|->>field" construct. This would function exactly the same as the current "|->field" construct, except it would return the saved stated of each field not the current field. For this to be useful, two additional special Qlingo would be needed:
    • SaveCloneRecord() - This function would copy current record values into the saved value. 
    • ClearCloneRecord() - This function would clear the saved values to 0's and empty strings.
    • These two functions would ONLY be valid within the pre-process and post-process states.
    • The initial value of the saved values would be 0's and empty strings.

There are many situations where this limited persistence would greatly expand the usefulness of XMPie and Qlingo without sacrificing anything. Today I work around these missing features by needing to preprocessing data, adding extra fields, and generally mucking about.

If a user does not want to utilize these features there is nothing that they need to change in any of the existing Qlingo.

For ease of development, the items 1,2, and 3 could be separated from item 4. I also guess that this expansion could be limited to uPlan, but I prefer to see it also in the desktop.

===

-Mark


--
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 http://groups.google.com/group/xmpie-users.
For more options, visit https://groups.google.com/d/optout.

Nick O

unread,
Sep 26, 2015, 6:52:15 PM9/26/15
to XMPie Interest Group
Mark - totally! I think all of that would be great additions to the language, and I have to say it seems like at least some of these enhancements should be on the table. I have a feeling that expansion of Qlingo is pretty low on the priority list because it's not shiny and a lot of customers (especially print customers like me) would have difficulty making the connections to business value. This unfortunately seems to be holding back the proliferation of truly compelling personalized marketing, IMHO.

In addition to what you described (or maybe it's the same thing, I am honestly not a particularly informed or intuitive developer) I would like the ability to manipulate the ADOR values for each record in different states or at different levels.

A very basic example of this is something I had to do this week: a bingo card populated by images of 24 different employees of a company. We did 100 cards and as you would imagine each one needed to have the images in a different sequence on the card. At first I was like "Oh! Easy!", but then I realized that you can't simply build an array and tell each ADOR to grab a random index while also keep track of which indices were in use. The Plan Interpreter seems to evaluate all ADORs at the same time, or at least independently of one another. Some way to set variables that are used to operate on specific sets of ADORs in specific sequences would be nice.

So what I had to do in this case was use javascript on a simple web page to take an array, shuffle it, and print it on the screen. Then I literally copied and pasted my 100 unique arrays into an Excel spreadsheet, used comma delimited 'Text to columns' to get each array value by itself and use THAT as my datasource. Seemed incredibly hackish/low-tech. But our client doesn't know the difference, and they were thrilled. Only lame thing about it is that this took me like 3 hours because I spent 2.5 hours mucking around in uPlan trying to make it work!

Then again, all of this may be possible and/or easy to do but I'm just not good enough with uPlan to realize it. If that's the case, though, why not make it more accessible for those of us using the software?

Just to be clear, I really like working with the XMPie products and don't intend this to be a gripe session. I'm sure that if they had the time and budget this sort of thing would be exactly what an engineering team wants to prioritize :)

couch

unread,
Sep 27, 2015, 3:04:43 AM9/27/15
to XMPie Interest Group
Mark,

Pre/post processing. It's an interesting idea. Again, I'd like to understand what you want to do. Any examples?

For your duplication of a record, why wouldn't you just create an ADOR that returns 1 (don't copy) and 2 (copy) and use the ADOR with the # of copies feature on the process page?

Nick,

I've done lottery draw style jobs where the "draw" is done using javascript or VBscript in uPlan. The logic uses an array and also checks to make sure the same number is not drawn twice. I've also done a custom playing card job for a casino where each pack of cards needed to be printed in random sequence each time, and with a personalized back. I've created date grids for personalized calendars (with custom birthdays, reminders, holidays and other events) by calling data as a userview and using UV2STR() to convert it to an InDesign table (using Adobe InDesign Tagged Text). Without looking too closely at a bingo application, I suspect similar techniques could be used here.

I'm not saying that uPlan is perfect, but there is a heck of a lot you can do with it when you have the time to work with it and think laterally.

While we are spit balling ideas, I'd like uPlan to be able to get data from a web service - or even from a standard XML file (rather than it having to be ADO recordset XML).

Your best chance to influence product managers is coming up with the XUG conference in Miami 25-28 October. http://www.xmpieusers.org/?page=2015ConferenceAgenda  Hounding them face to face is priceless ;-)
Reply all
Reply to author
Forward
0 new messages