Start a new topic

How to get the previous versions of an item

Using SystemWeaver Script Language, it is possible to get the previous version(s) of an item, as shown below in the grid definition.


The grid definition uses:

  • PrevVersion: returns the previous version of the item.
  • ApplyTemplate.. WithParam: calls a template with parameters.
  • Template: defines a template to be used several times in a script.



Grid Definition:

<Grid>
<Columns>
<ItemNameColumn width="200" />  
<ItemVersionColumn/> 
</Columns>  
<!--First call for the "PreviousVersions" template, with two initial values for the parameters -->
<ApplyTemplate name="PreviousVersions">  
<WithParam name="p1" select="."/> 
<WithParam name="p2" select="[]"/> 
</ApplyTemplate>

<!--Get Previous Versions, if there is any-->
<Template name="PreviousVersions">
<Parameter name="p1" as="Item"/>  
<Parameter name="p2" as="[Item]"/>  
<Row> 
<!--Get Previous Version, if there is one-->
<ForEach select="PrevVersion[Handle != '' ]">   
<Variable name="CurrentItem" as="Items" select="."/>
<Variable name="Accumulated" as="Items" select="$p1 union $p2"/>
<!--Recursive calling for the template, with updated values for the parameters -->
                <ApplyTemplate name="PreviousVersions">  
                    <WithParam name="p1" select="."/>
                    <WithParam name="p2" select="$Accumulated"/>  
                </ApplyTemplate> 
            </ForEach>
        </Row>
    </Template>
</Grid>

 

 

 

 Result:

Thanks,

Bashar



 

Login to post a comment