Freeze / unfreeze external work items

Description
Polefarer
Posts: 3
Joined: Tue Jun 11, 2019 8:43 am

Freeze / unfreeze external work items

Postby Polefarer » Wed Jun 12, 2019 12:07 pm

Hello,
Just for those who has an interest... I created a wiki script to get change reference on all external work items (referenced from another document, such as when branched) in a document. Thus, it is possible to unfreeze or freeze all work items in one go. This is especially nice if one made a document branch (at a time) with wrong type of reference, and do not want to delete the document to branch again in order to f.ex unfreeze all work items.

Here is the code:

Code: Select all

#set($moduleManager = $trackerService.getModuleManager())   
##Get space
#set($space = $page.space.name)
##Get project
#set($project = $projectService.getProject($page.getProject()))
##Get location for space
#set($docsLocation = $project.location.getLocation($space))
##Get list of documents in location/space
#set($docList = $trackerService.moduleManager.getModules($project,$docsLocation))   
##Init variables
#set($docArray="")
#set($baselineRevArray="")

##Get list of baselines
#set($trackerProject = $trackerService.getTrackerProject($page.getProject()))
#set($baselineManager = $trackerProject.getBaselinesManager())
#set($baseline = $baselineManager.getBaselines())

##Loop through all baselines, get revision number and make comma separated string
#foreach ($i in $baseline.listIterator())
   ##Get Baseline Revision no. and create comma separated string
   #if($baselineRevArray == "" || !$baselineRevArray)
      #set($baselineRevArray = "${i.getLocalId().getObjectName()}")
   #else
      #set($baselineRevArray = "${baselineRevArray},${i.getLocalId().getObjectName()}")
   #end
#end


##Make comma separated string of documents in current space
#foreach($d2 in $docList)
   ## Check if documents are readable and resolvable.
   #if($d2.can().read() && !$d2.isUnresolvable())
      ##Get Document Names and create comma separated string
      #if($docArray == "" || !$docArray)
         #set($docArray = "${d2.getModuleName()}")
      #else
         #set($docArray = "${docArray},${d2.getModuleName()}")
      #end
   #end
#end


##Create parameter with documents
{parameter:doc|type=enum|allowed-values=$docArray|value=}
##Create parameter with choices for reference types
{parameter:refType|type=enum|value=liveRef|allowed-values=Live Reference>liveRef,Frozen Reference>frozenRef}
##Create parameter with baselines
{parameter:baselineRev|type=enum|allowed-values=$baselineRevArray|value=}


1 Change reference of external work items

Work items placed in a document as a referenced item to the original, f.ex. in a branched document, have to manually be changed after the initial branch performed. To reduce workload this script helps change all external referenced work items from frozen (locked to a revision) to unfrozen (live), or vice versa, in one go.

*Example:* A MASTER document was accidentally branched where the branch has referenced work items locked (frozen) to a specific revision, thus need to unfreeze all work items, making them live references.


-------------------------------------
*Choose document, desired reference type and click Apply.*
Only documents (modules) contained in work space where this script is placed are selectable.
Revision no is only applicable if reference type 'Frozen Reference' is chosen, else ignored.

##Create pull-down lists for action only if documents exist
#if($docArray != "" && $docArray)
   -------------------------------------
   ##Create pull-down lists for selection
   {parameter-form}
      <div style="width:600px">
         {table:header=no|border=no}
            Document | {parameter-editor:doc|width=200}
            Reference Type | {parameter-editor:refType|width=200}
            Revison No. | {parameter-editor:baselineRev|width=200}
            {parameter-form-submit} 
         {table}
      </div>
   {parameter-form}
#else
   -------------------------------------
   *Error!* No documents found in space.
   -------------------------------------
#end

#if($pageParameters.doc && $pageParameters.refType)
   #set($foundDoc = false)
   ##Loop through all documents in space and find selected document
   #foreach($d2 in $docList)
      #set($modLen = 0)
      ## Check if documents are readable and resolvable.
      #if($d2.can().read() && !$d2.isUnresolvable())
         ##Get selected document by checking name
         #set($modTitle = "$pageParameters.doc.getName()")
         #set($modLen = $d2.getModuleName().length())
         #set($modTitle = $modTitle.substring(0,$modLen))
         ##Correct document found if name matched and not previously found
         #if($d2.getModuleName() == ${modTitle} && !$foundDoc)
            ##Set document to use
            #set($docChosen = $d2)
            ##prevent accidentally setting document again
            #set($foundDoc = true)
         #else
            *Error!* Document name selected does not match module! <br>
            Name from module: $d2.getModuleName(). Length: $modLen<br>
            Name from selection: ${modTitle}<br>
         #end
      #end
   #end

   ##Get all external worktiems in document (work items referenced from other documents)
   #set($extWorkItems = $docChosen.getExternalWorkItems())

   ##Macro for unfreezing one work item at a time
   #macro(unfreezeItems $item $doc)
      ## Check if workitem is readable and resolvable.
      #if($item.can().read() && !$item.isUnresolvable())
         ##Unfreeze work item
         #set($test = $doc.unfreezeExternalWorkItem($item))
         * {workitem:$item.id|display=long}* - Set to be live reference (unfrozen)
      #end
   #end

   ##Macro for freezing one work item at a time
   #macro(freezeItems $item $doc $rev)
      ## Check if workitem is readable and resolvable.
      #if($item.can().read() && !$item.isUnresolvable())
         ##freeze work item
         #set($test = $doc.freezeExternalWorkItem($item, "$rev"))
         * {workitem:$item.id|display=long}* - Set to be frozen reference to revision "$rev"
      #end
   #end
   
   1.1 Results
   $transactionService.beginTx()
      #if($pageParameters.refType.id == "liveRef")
         #foreach($i in $extWorkItems)
            #unfreezeItems($i $docChosen)
         #end
         $docChosen.save()
      #elseif($pageParameters.refType.id == "frozenRef")
         #if(!$pageParameters.baselineRev)
            -------------------------------------
            *Error!* Revision No. not specified
            -------------------------------------
         #else
            #foreach($i in $extWorkItems)
               #freezeItems($i $docChosen $pageParameters.baselineRev.id)
            #end
            $docChosen.save()
         #end
      #end
   $transactionService.commitTx()

   DONE
#end

Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 9 guests