Iterator on child database publishing

We are publishing a content type out to a database. This content type contains a slot that can contain files (e.g. PDFs). I am trying to publish the title and url for said PDFs in a child data base. The issue is that I can only publish a single PDF url to all the child rows because I cannot progress through the list of content in the slot with an iterator for each new row in the child table.

Binding examples:

$db.child[1]	"CMS_ACCESSORY_LINKS"
$slotcontent	$user.psoSlotTools.getSlotContents($sys.assemblyItem,"crpAccessoryLinks",$params)
$child[1].ACCESSORY_LINK_URL	$rx.location.generate($slotcontent.get(0))

What I need is a way to replace the 0 in the third binding with a variable that iterates with each new row to the CMS_ACCESSORY_LINKS table (or which is based on the current item index in $slotcontent).

Any ideas would be greatly appreciated,
Cade

When you are mapping to a child column in the destination database it is expecting to be provided a List of the values e.g. holding the value for each child row. e.g. for a multi valued field you can use $sys.item.getProperty(“fieldname”).getValues() which returns a list. If you just want a particular child field you can extract this list using $rx.asmhelper.childValues(parentNode,childName,propertyName). as you are using a function on the node itself you would have to use a loop and populate a list. Creating an empty list is not so straightforward in this version of jexl, you can use the $user.psoListTools.asList(null); The parameter here is a single object you want to wrap in a list, if you pass null it will be an empty list. In jexl you can have multiple lines, the last statement that returns a value is what is set to the variable on the left side of the binding. I have not tested this but something like the following may return a list of locations as required.

Just a warning though, this does not work for snippets in the slot containing external links etc, as you cannot use $rx.location.generate unless there is a real location scheme for the item. Another way to get around this is by using a standard binding on your templates e.g. $pagelink. You can access the bindings on the assembled snippet like this $slotitem.getBindings().get(’$pagelink’) (may need to escape the $). The actual template can then use whatever mechanism it likes to generate the link.

Left = $child[1].ACCESSORY_LINK_URL

Right =

    
$newList = $user.psoListTools.asList(null);
    for ($slotitem : $slotcontent) {
       $newList.add($rx.location.generate($slotitem));
    };
    $newList;

This worked perfectly. Thanks for the info!

I am trying to repeat this solution in my environment, but I am failing horribly:

All signs point to the fact that the for loop is not working in my binding. I have set up two test variables in my bindings, they look like this:

left side: $test; right side:

 $links = $user.psoListTools.asList(null); for($slotitem:$slotcontent){ $links.add($rx.location.generate($slotitem,'cltPgTopic',null)); } $links;

produces error: $test=Problem parsing expression: $links = $user.psoListTools.asList(null); for($slotitem:$slotcontent){ $links.add($rx.location.generate($slotitem,‘cltPgTopic’,null)); } $links; at character 44

left side: $test2; right side:

 $y=0; for($x=0;$x>10;$x++){ $y = $y + 1; } $y;

produces error: $test2=Problem parsing expression: $y=0; for($x=0;$x>10;$x++){ $y = $y + 1; } $y; at character 7

I have looked at the documentation for java’s for loop, and it would appear that both “signatures” are acceptable, one being a traditional for loop, the other being more like a foreach, but neither seems to work as a binding in my database template.

Any ideas on what I can try?

Thanks,

-J

Nevermind. I changed to this form:


$links = $user.psoListTools.asList(null);
foreach($slotitem in $slotcontent){
    $links.add($rx.location.generate($slotitem,'cltPgTopic',null));
}
$links

and it’s working now.