Automated document reference list

Description
Salmolin
Posts: 14
Joined: Mon Sep 21, 2015 5:54 am

Automated document reference list

Postby Salmolin » Thu Jan 31, 2019 8:07 am

Hi

I would like to generate an automated document reference list in a document. Automated means, the list is automatically generated, if I use one "tag" inside the document. I have defined for every document reference a workitem.
So I would like to create a script, that searches inside a document after these "tags" and create the reference list on the top of the document itself. At the end, I would like to include this in a macro to call it on every document.

- How can I get the documents content?
- How can I search through the document content after a specified "tag"?

I'm not that familiar with this kind of scripting, every help will be welcome.

Jürgen
Posts: 89
Joined: Tue Sep 12, 2017 1:02 pm

Re: Automated document reference list

Postby Jürgen » Thu Jan 31, 2019 1:30 pm

Hi, Salmolin

Let me repeat that in my words to see if I understand your question.

- you have work items of the type "document"
- you have a live doc (a polarion document) that contains these "document" work items
- some of these work items contain a "tag"
- these specific work items shall additionally be listed at the top of the live doc?

This sounds a bit strange, but right now I would assume that you really do not need to search tags in a live doc, but you rather would search for work items in that live doc, which contain the tag, and then display them at the top.

So you might need a macro, contained in the live doc at the top, that does a work item query for the tag, and then displays the result somehow.

Salmolin
Posts: 14
Joined: Mon Sep 21, 2015 5:54 am

Re: Automated document reference list

Postby Salmolin » Thu Jan 31, 2019 4:21 pm

Hi

Thank you for your fast reply.
I try to be more clear.

Document 1
This document contains many document description Items (Work Items). THis wi describes document and containing also a "tag" which shall be used in other documents (i.e. document 2) as a reference, inside the document content.

Work Item 1: User-Manual / tag: "/user_man/"
Work Item 2: Maintenance Manual / tag: "/main_man/"


Document 2
This document is a specification of a product. This document contains textes (general text and text in work items).

text text text, with reference to /user_man/.

Now, I would like to have a macro, which searches "tags" inside the document 2 (here /user_man/). Based on this "tag" the related document description item (work item 1 in document 1) shall be found. With using this WI, I get the description of the User Manual (according to WI 1) which can then be used for the reference table in Document 2

Result:
I can specify my product in the specification document and can use references like /user_man/. Based on the "tags" found in the document, the auto generated table will add the related document description (based on the document description item).

Is this description more clear now?

Jürgen
Posts: 89
Joined: Tue Sep 12, 2017 1:02 pm

Re: Automated document reference list

Postby Jürgen » Wed Feb 06, 2019 6:46 am

Ich habe prinzipiell zwei Lösungsideen, allerdings aus Zeitgründen nur als Draft.

1. Die eleganteste Lösung wäre vermutlich, ein SQL-Query zu definieren, das etwa folgendes macht:
select id, title from work item where document.id = "document_1" and tag in (select distinct tag from work item where document.id = "document_2")

Also sinngemäß. Ich kenne die Tabellenstrukturen in polarion nicht wirklich.

2. Ein script schreiben, das zunächst alle Work Items des zweiten Dokuments durchläuft und dabei eine Liste mit den benutzten Tag-Namen aufbaut. Mit dieser Liste kann man dann die WI aus dem ersten Dokument suchen und von denen ID und Titel darstellen.

Ich bin sicher, hier im Forum gibt es bereits Beispiele, wie man alle WI eines Dokuments findet, und auch, wie man bestimmte infos ausgibt.


Generell: Wäre es nicht sinniger, die Work Items aus den beiden Dokumenten zu verlinken, anstatt einzelne Tags zu definieren, die im Prinzip dasselbe tun?

Salmolin
Posts: 14
Joined: Mon Sep 21, 2015 5:54 am

Re: Automated document reference list

Postby Salmolin » Fri Feb 22, 2019 6:54 am

Danke für deine Ausführungen.

Ich habe nun Option 2 realisiert.
Leider können 'nur' WI Inhalte durchsucht werden un nicht das Dokument selbst, was bedeuted, dass jeder Text in ein WI verpackt werden muss. Ist aber nicht weiter schlimm.

Danke für deine Hilfe.

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

Re: Automated document reference list

Postby Polefarer » Tue Jun 11, 2019 9:06 am

For anyone that is interested:
I made a wiki content script that looks for all workitems of type "refDocument" and which are linked to any workitem in the current document that the wiki script is used in, then makes a sorted list for these... I use this as an automatically generated reference table. You can modify it to your needs if you want.


Code: Select all

##******Code for generating a table of work items of type Referenced Document that has been linked to in containing work itmes**********
#set ($project_id = $page.getSpace().getProjectId())
#set ($proj = $projectService.getProject($project_id))
#set ($myquery = "type:refDocument")
#set ($sortRows = "id" )
#set ($foundList = "")
#set ($found = $objectFactory.newSet()) ## Creating empty array

##DEBUG
#set ($countUnresolvableWIs = 0)
#set ($countResolvableLinks = 0)
#set ($countResolvableModules = 0)
#set ($countUnresolvableModules = 0)
#set ($unresolvedIssues = false)


##create collection of work items from query
#set ($items = $trackerService.queryWorkItems($proj,$myquery,"$sortRows"))

#foreach ($wi in $items)
   ##DEBUG
   ##$wi.can().read()
   ##$wi.isUnresolvable()

   ##Check if work item is readable (permissions) and if it is resolvable.
   #if ($wi.can().read() && !$wi.isUnresolvable())
      #foreach ($link in $wi.getLinkedWorkItemsStructsBack())
      
         ##Check if module is readable (permissions) and if it is resolvable.
         #if ($link.getLinkedItem().getModule().can().read() && !$link.getLinkedItem().getModule().isUnresolvable())
            #set ($linkedModule = $link.getLinkedItem().getModule())
            #set ($linkedModuleName = $linkedModule.getModuleName())

            ##if WI has link with role 'reference' and the linked item resides in current document, then make list of IDs
            #if ($link.getLinkRole().id == "reference" && $linkedModuleName == "$page.name")
               #set ($existsCount = 0)
               #set ($linked = $link.getLinkedItem())

               ##Loop through array and count if work item has been found before
               #foreach ($j in $found)
                  #if($j == $wi.id)
                     ##found existing...
                     #set ($existsCount = $existsCount + 1)
                  #end   
               #end
               ##Debug code
               ##existsCount: $existsCount <br>

               ##if workitem has not been added to array before, then add to array
               #if ($existsCount <= 0)
                  ##Collect found linked work items in array
                  #set($temp = $found.add($wi.id))

                  ##Create list of IDs to use in workitems query
                  #if (!$foundList || $foundList == "")
                     ##set first item in list of IDs
                     #set ($foundList = "id:$wi.id")
                  #else
                     ##Concatinate all ids of linked work items
                     #set ($foundList = "$foundList id:$wi.id")
                  #end
               #end
            #end   
         #else
            ##DEBUG
            ERROR-MESSAGE: An error occurred...
            #set ($unresolvedIssues = true)
            #set ($countUnresolvableModules = $countUnresolvableModules+1)
            Module title: $linkedModule.getTitle() <br>
            Module unresolvable $link.getLinkedItem().getModule().isUnresolvable() <br>
         #end
      #end
   #else
      ##DEBUG
      ERROR-MESSAGE: An error occurred...
      #set ($unresolvedIssues = true)
      #set ($countUnresolvableWIs = $countUnresolvableWIs+1)
      Work item unresolvable, ID: $wi.id <br>
   #end
#end

#if ($unresolvedIssues)
   ERROR-MESSAGE: An error occurred...
   countUnresolvableWIs: $countUnresolvableWIs <br>
   countUnresolvableModules: $countUnresolvableModules <br>
   $linkedModuleName <br>
   $foundList <br>
#end
##DEBUG
##$linkedModuleName <br>
##$foundList <br>

#if ($foundList == "")
   NO REFERENCED DOCUMENTS FOUND!
#else
   ##Create table using workitems macro defined in Wiki Syntax Help
   The following documents have been referenced in this document:
   {workitems: query= $foundList | fields=id as image-text,referenceID,title,referenceType,referenceRevision,status as image-text | sortby=id}
#end
##*****************************************************************


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: BrianPrick and 6 guests