Updating Field of Content Item upon Assembling Item

Hi there.

I’m wondering if Percussion is able to update a field of a content item (say, a sys_HiddenInput field) based on the results of the item’s assembly.

For example, if an item renders a slot during its assembly, does Percussion have a method (accessible via Velocity) that would let me store the number of items that the slot returned to a hidden field of that item.

The code might look something like this:

$rx.some_object.setFieldValue($sys.item,"hidden_field",$sys.currentslot.relresults.size())

The use case I have in mind is to store the number of items that an auto-index returns on the auto-index itself, and then (1) display that metadata in inline variants that link to the auto-index and (2) hide that auto-index in dropdowns if it returns no items.

Maybe other folks can think of more situations where this ability would be useful.

Thanks.

there are save methods… never used them though.

You can use these Inspection Macros to find out the exact method names.

If memory serves, you’d want to do something like:

$someItem.getProperty(‘rx:field_name’).setValue($some_value)

and then something like:

$someItem.save()

Again, it’s been a while since I’ve inspected the Item and Property classes so I may have the methods wrong.

Just a quick update…

I’ve found that you cannot update a content item from Velocity, since Percussion has not implemented any of the JSR-170 save/set methods. However, you can create a database template that writes back to the content items it assembles (basically, the database template just writes back to the Percussion repository). In my case, I’m using “self-referencing” database templates to store how many and what items an auto-index lists, and whether the next incremental publish should include the auto-index. I use this metadata to check if an auto-index is empty before including it in a list of links, and if it is not empty, to display how many items the auto-index lists next to its link.