{"id":636,"date":"2014-08-01T18:28:26","date_gmt":"2014-08-02T01:28:26","guid":{"rendered":"https:\/\/blogs.plm.automation.siemens.com\/t5\/Polarion-Blog\/Tech-Tips-amp-Tricks-Querying-across-Documents-for-unlinked-Work\/ba-p\/380866"},"modified":"2026-03-26T05:29:29","modified_gmt":"2026-03-26T09:29:29","slug":"tech-tips-tricks-querying-across-documents-for-unlinked-work-items","status":"publish","type":"post","link":"https:\/\/blogs.sw.siemens.com\/polarion\/tech-tips-tricks-querying-across-documents-for-unlinked-work-items\/","title":{"rendered":"Tech Tips &#038; Tricks: Querying across Documents for unlinked Work Items"},"content":{"rendered":"<p>Here&#8217;s another in our series of tips and tricks from the Polarion Software Technical Support team, in which we share solutions we provided to customers for real-world use cases that. The same tips might help you too, or others on your team. Let&#8217;s look today at how to query to discover unlinked Work Items across Polarion LiveDocs.<br \/>\n<!--more--><br \/>\n<H2>Use Case<\/H2><br \/>\nTwo Documents within a project having linked Work Items with related to link role, like this:<br \/>\n<PRE style=\"line-height: normal; border: 1px dashed #999; background-color: #f8f8f8; padding: 10px;\">Doc1<br \/>\nWI-1, related to WI-3<br \/>\nWI-2, related to WI-7 <\/p>\n<p>Doc2<br \/>\nWI-3, related to WI-1, parent of WI-4<br \/>\nWI-4, has parent WI-3, related to Wi-6<br \/>\nWI-5, no link to Doc1, parent of WI-6<br \/>\nWI-6, has parent WI-5, related to WI-4<br \/>\nWI-7, related to WI-2<\/PRE><br \/>\nYou want to find all Work Items on the parent level in Doc2 that are NOT linked to a Work Item in Doc1. This means that the query must return WI-5, and NOT WI-4 or WI-6, as they are linked within Doc2 to another item in Doc2.<br \/>\n<P style=\"text-align: center;\"><A href=\"http:\/\/community.plm.automation.siemens.com\/legacyfs\/online\/siemensplm_blogs\/2014\/05\/docs-without-parent.png\" rel=\"nofollow noopener noreferrer\"><IMG class=\"alignnone size-full wp-image-5613\" src=\"http:\/\/community.plm.automation.siemens.com\/legacyfs\/online\/siemensplm_blogs\/2014\/05\/docs-without-parent.png\" alt=\"Query results in Polarion web interface\" width=\"700\" height=\"543\" \/><\/A><\/P><\/p>\n<p><H2>Solution<\/H2><br \/>\nOnce again we&#8217;re transported from the realm of Lucene to the realm of SQL, making use of the background SQL database in Polarion that mirrors the Subversion repository data, and enables speedy complex queries that Lucene either can handle, or would have to be done in such a way as to bog down the system while the query is processed. Here is some example Wiki mark-up and code that provides a solution to our use case.<br \/>\n<PRE style=\"line-height: normal; border: 1px dashed #999; background-color: #f8f8f8; padding: 10px;\">#set($projectId = $page.getProject())<\/p>\n<p>1 Items from Doc2 without parent requirement in Doc2<\/p>\n<p>#set($my1Query = &#8220;SELECT item.C_PK FROM WORKITEM item, PROJECT proj, MODULE doc2 =&gt;<br \/>\nWHERE proj.C_ID = &#8216;${projectId}&#8217; AND doc2.C_ID = &#8216;Doc2&#8217; AND doc2.C_MODULEFOLDER = =&gt;<br \/>\n&#8216;My_Space&#8217; AND doc2.FK_URI_PROJECT = proj.C_URI AND item.C_TYPE = &#8216;requirement&#8217; AND =&gt;<br \/>\nitem.FK_URI_MODULE = doc2.C_URI AND NOT EXISTS (SELECT link.* FROM =&gt;<br \/>\nSTRUCT_WORKITEM_LINKEDWORKITEMS link, WORKITEM parent WHERE link.C_ROLE = &#8216;parent&#8217; =&gt;<br \/>\nAND link.FK_URI_P_WORKITEM = item.C_URI AND link.FK_URI_WORKITEM = parent.C_URI =&gt;<br \/>\nAND parent.C_TYPE = &#8216;requirement&#8217; AND parent.FK_URI_MODULE = doc2.C_URI)&#8221;)<\/p>\n<p>{workitems:sqlQuery=$my1Query}<\/p>\n<p>1 Items from Doc2 not linked to Doc1<\/p>\n<p>#set($my2Query = &#8220;SELECT item.C_PK FROM WORKITEM item, PROJECT proj, MODULE doc2 =&gt;<br \/>\nWHERE proj.C_ID = &#8216;${projectId}&#8217; AND doc2.C_ID = &#8216;Doc2&#8217; AND doc2.C_MODULEFOLDER = =&gt;<br \/>\n&#8216;My_Space&#8217; AND doc2.FK_URI_PROJECT = proj.C_URI AND item.C_TYPE = &#8216;requirement&#8217; =&gt;<br \/>\nAND item.FK_URI_MODULE = doc2.C_URI AND NOT EXISTS (SELECT link.* FROM =&gt;<br \/>\nSTRUCT_WORKITEM_LINKEDWORKITEMS link, WORKITEM neighbour, MODULE doc1 WHERE =&gt;<br \/>\nlink.FK_URI_P_WORKITEM = item.C_URI AND link.FK_URI_WORKITEM = neighbour.C_URI AND =&gt;<br \/>\nneighbour.FK_URI_MODULE = doc1.C_URI AND doc1.C_ID = &#8216;Doc1&#8217; AND =&gt;<br \/>\ndoc1.C_MODULEFOLDER = &#8216;My_Space&#8217; AND doc1.FK_URI_PROJECT = proj.C_URI)&#8221;)<\/p>\n<p>{workitems:sqlQuery=$my2Query}<\/p>\n<p>1 The complete solution<\/p>\n<p>#set($my3Query = &#8220;SELECT item.C_PK FROM WORKITEM item, PROJECT proj, MODULE doc2 =&gt;<br \/>\nWHERE proj.C_ID = &#8216;${projectId}&#8217; AND doc2.C_ID = &#8216;Doc2&#8217; AND doc2.C_MODULEFOLDER = =&gt;<br \/>\n&#8216;My_Space&#8217; AND doc2.FK_URI_PROJECT = proj.C_URI AND item.C_TYPE = &#8216;requirement&#8217; =&gt;<br \/>\nAND item.FK_URI_MODULE = doc2.C_URI AND NOT EXISTS (SELECT linked.C_PK FROM =&gt;<br \/>\nSTRUCT_WORKITEM_LINKEDWORKITEMS link, WORKITEM linked WHERE link.C_ROLE = &#8216;parent&#8217; =&gt;<br \/>\nAND link.FK_URI_P_WORKITEM = item.C_URI AND link.FK_URI_WORKITEM = linked.C_URI AND =&gt;<br \/>\nlinked.C_TYPE = &#8216;requirement&#8217; AND linked.FK_URI_MODULE = doc2.C_URI UNION SELECT =&gt;<br \/>\nlinked.C_PK FROM STRUCT_WORKITEM_LINKEDWORKITEMS link, WORKITEM linked, MODULE doc1 =&gt;<br \/>\nWHERE link.FK_URI_P_WORKITEM = item.C_URI AND link.FK_URI_WORKITEM = linked.C_URI =&gt;<br \/>\nAND linked.FK_URI_MODULE = doc1.C_URI AND doc1.C_ID = &#8216;Doc1&#8217; AND =&gt;<br \/>\ndoc1.C_MODULEFOLDER = &#8216;My_Space&#8217; AND doc1.FK_URI_PROJECT = proj.C_URI)&#8221;)<\/p>\n<p>{workitems:sqlQuery=$my3Query}<\/PRE><br \/>\n<P style=\"font-size: smaller; text-align: right;\">=&gt; indicates continuation on the same line.<\/P><\/p>\n<p><HR \/><\/p>\n<p><EM>Jiri Jandl is a Senior Support Engineer with Polarion Software&#8217;s European tech support team. He is based in Prague, Czech Republic.<\/EM><\/p>\n<p><HR \/><br \/>\n<P style=\"text-align: center;\"><A href=\"http:\/\/www.polarion.com\/techsupport\/index.php#support-level\" rel=\"nofollow noopener noreferrer\"><IMG class=\"alignnone size-full wp-image-5839\" src=\"http:\/\/community.plm.automation.siemens.com\/legacyfs\/online\/siemensplm_blogs\/2014\/06\/polarion-silver-gold-support.jpg\" alt=\"Banner: It's all about solutions - Polarion Silver and Gold Support\" width=\"700\" height=\"150\" \/><\/A><\/P><br \/>\n<P style=\"text-align: left;\"><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s another in our series of tips and tricks from the Polarion Software Technical Support team, in which we share solutions we provided to customers for real-world use cases that. The same tips mi&#8230;<\/p>\n","protected":false},"author":54129,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spanish_translation":"","french_translation":"","german_translation":"","italian_translation":"","polish_translation":"","japanese_translation":"","chinese_translation":"","footnotes":""},"categories":[1],"tags":[],"industry":[],"product":[],"coauthors":[],"class_list":["post-636","post","type-post","status-publish","format-standard","hentry","category-news"],"_links":{"self":[{"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/posts\/636","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/users\/54129"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/comments?post=636"}],"version-history":[{"count":1,"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/posts\/636\/revisions"}],"predecessor-version":[{"id":637,"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/posts\/636\/revisions\/637"}],"wp:attachment":[{"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/media?parent=636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/categories?post=636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/tags?post=636"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/industry?post=636"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/product?post=636"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/polarion\/wp-json\/wp\/v2\/coauthors?post=636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}