Is there an easy way to access the LASTTRANSITIONDATE field on the ContentStatus table for an item in velocity?
Jay,
I’d have to say that there’s no easy way. It looks like we intended this to be part of the PSComponentSummary, but unfortunately, it’s not implemented.
If you want to try to do this the hard way, use $rx.db.get() to perform a SQL query.
Dave
Thanks, I’ve figured out the $rx.db.get() but now I run into a problem
My code:
#set($sqlContentID = $sys.item.getProperty(‘rx:sys_contentid’).String)
#set($sqlContentTypeID = $sys.item.getProperty(‘rx:sys_contenttypeid’).String)
#set($sqlQuery = “SELECT LASTTRANSITIONDATE FROM CONTENTSTATUS WHERE CONTENTTYPEID = ‘$sqlContentTypeID’ AND CONTENTID = ‘$sqlContentID’”)
#set($sqlResult = $rx.db.get("", $sqlQuery))
#set($sqlFirstRow = $sqlResult.get(0))
Now $sqlFirstRow contains a mapping how do I get my LASTTRANSITIONDATE date out of the mapping so I can use the $tools.date.format() on it?
According to the JavaDoc for com.percussion.services.assembly.jexl.PSDbUtils (which is what $rx.db really is), the return type of the get() method is List<Map<String,Object>>.
This means that $sqlFirstRow will contain a Map<String,Object>.
$sqlFirstRow.get(‘LASTTRANSITIONDATE’) should return a java.sql.Date Object, which should be what the second parameter to $tools.date.format() is expecting.
If this doesn’t work, try outputing $sqlFirstRow and see what kind of object it is.
This is one reason why I like to put these kinds of formulas in the Bindings rather than in the Velocity Source. In the Bindings, you can switch to the “debug” preview, and it will tell you the types and values of your variables.
Dave
Thank you that worked.