Clarity

Expand all | Collapse all

Multi Level Hierarchical Portlet

  • 1.  Multi Level Hierarchical Portlet

    Posted Jul 13, 2009 03:00 PM
    Is there a way to create a Multi Level (children, grand children, etc) Hierarchical portlet in Clarity?    


  • 2.  Re: Multi Level Hierarchical Portlet

    Posted Jul 14, 2009 04:24 AM
    Hi Chris  Yes, you need to build a union query using some specific columns so that Clarity knows you are creating a hierarchy.   This thread  gives you some sample code.  Owen


  • 3.  Re: Multi Level Hierarchical Portlet

    Posted Jul 14, 2009 04:59 AM
    Chris,  OBS and sub / master project relations are good examples in clarity for Hierrachy.You might have the query to retrieve that,so you can use that in Nsql -Portlet.  Regards,  sundar


  • 4.  Re: Multi Level Hierarchical Portlet

    Posted Jul 14, 2009 07:19 AM
    I'm able to create a a Hierarchical portlet that is 1 level deep. Not sure how to create one that would be 2 or 3 levels deep.  


  • 5.  Re: Multi Level Hierarchical Portlet

    Posted Jul 15, 2009 07:22 AM
    Chris,

    Pls create this view and use it in your Query.

    CREATE OR REPLACE VIEW UV_OBS_LEVELS
    (LEVEL1_ID, LEVEL1_NAME, LEVEL1_DEPTH, LEVEL2_ID, LEVEL2_NAME,
    LEVEL2_DEPTH, LEVEL3_ID, LEVEL3_NAME, LEVEL3_DEPTH, LEVEL4_ID,
    LEVEL4_NAME, LEVEL4_DEPTH, LEVEL5_ID, LEVEL5_NAME, LEVEL5_DEPTH,
    LEVEL6_ID, LEVEL6_NAME, LEVEL6_DEPTH, LEVEL7_ID, LEVEL7_NAME,
    LEVEL7_DEPTH, LEVEL8_ID, LEVEL8_NAME, LEVEL8_DEPTH, LEVEL9_ID,
    LEVEL9_NAME, LEVEL9_DEPTH, LEVEL10_ID, LEVEL10_NAME, LEVEL10_DEPTH,
    OBS_PATH)
    AS
    SELECT A.ID LEVEL1_ID, A.NAME LEVEL1_NAME, A.DEPTH LEVEL1_DEPTH, B.ID LEVEL2_ID, B.NAME LEVEL2_NAME, B.DEPTH LEVEL2_DEPTH
    , C.ID LEVEL3_ID, C.NAME LEVEL3_NAME, C.DEPTH LEVEL3_DEPTH, D.ID LEVEL4_ID, D.NAME LEVEL4_NAME, D.DEPTH LEVEL4_DEPTH
    , E.ID LEVEL5_ID, E.NAME LEVEL5_NAME, E.DEPTH LEVEL5_DEPTH, F.ID LEVEL6_ID, F.NAME LEVEL6_NAME, F.DEPTH LEVEL6_DEPTH
    , G.ID LEVEL7_ID, G.NAME LEVEL7_NAME, G.DEPTH LEVEL7_DEPTH, H.ID LEVEL8_ID, H.NAME LEVEL8_NAME, H.DEPTH LEVEL8_DEPTH
    , I.ID LEVEL9_ID, I.NAME LEVEL9_NAME, I.DEPTH LEVEL9_DEPTH, J.ID LEVEL10_ID, J.NAME LEVEL10_NAME, J.DEPTH LEVEL10_DEPTH
    , CASE WHEN J.ID IS NOT NULL THEN J.NAME || '/' END || CASE WHEN I.ID IS NOT NULL THEN I.NAME || '/' END
    || CASE WHEN H.ID IS NOT NULL THEN H.NAME || '/' END || CASE WHEN G.ID IS NOT NULL THEN G.NAME || '/' END
    || CASE WHEN F.ID IS NOT NULL THEN F.NAME || '/' END || CASE WHEN E.ID IS NOT NULL THEN E.NAME || '/' END
    || CASE WHEN D.ID IS NOT NULL THEN D.NAME || '/' END || CASE WHEN C.ID IS NOT NULL THEN C.NAME || '/' END
    || CASE WHEN B.ID IS NOT NULL THEN B.NAME || '/' END || CASE WHEN A.ID IS NOT NULL THEN A.NAME || '/' END OBS_PATH
    FROM
    PRJ_OBS_UNITS A
    , PRJ_OBS_UNITS B
    , PRJ_OBS_UNITS C
    , PRJ_OBS_UNITS D
    , PRJ_OBS_UNITS E
    , PRJ_OBS_UNITS F
    , PRJ_OBS_UNITS G
    , PRJ_OBS_UNITS H
    , PRJ_OBS_UNITS I
    , PRJ_OBS_UNITS J
    WHERE
    A.PARENT_ID = B.ID(+)
    AND B.PARENT_ID = C.ID(+)
    AND C.PARENT_ID = D.ID(+)
    AND D.PARENT_ID = E.ID(+)
    AND E.PARENT_ID = F.ID(+)
    AND F.PARENT_ID = G.ID(+)
    AND G.PARENT_ID = H.ID(+)
    AND H.PARENT_ID = I.ID(+)
    AND I.PARENT_ID = J.ID(+)
    /

    Regards,
    sundar


  • 6.  Re: Multi Level Hierarchical Portlet



  • 7.  Re: Multi Level Hierarchical Portlet

    Posted Jul 16, 2009 07:18 AM
    Siva/Sunder,  Thanks for the input.  Where we are facing a challenge is the is it even possible to have a multi level HGrid Portlet i.e you have a Parent at the highest level and then in the HGrid portlet you click on the "+" sign and it shows the children with a "+" sign next to the child record if there are grand children and when you click the "+" sign it shows the Grand children and so on.  If this is possible how would we use the hg_row_id   parameter and would we create multiple parameters and how would that impact the NSQL?      


  • 8.  RE: Re: Multi Level Hierarchical Portlet

    Posted Mar 31, 2011 11:21 AM
    I am having a similar issue. I have been able to create a hierarchical portlet that goes 1-level deep (parent-child portfolio) and now am trying to go deeper to show investments within those child portfolios. Does anyone have a sample or the knowledge of how this is done?

    Thanks


  • 9.  RE: Re: Multi Level Hierarchical Portlet

    Posted Apr 01, 2011 04:09 AM
    I do not have a sample code at hand but here's the idea on how it can be done:

    The Hierarchical portlet is driven by HG_HAS_CHILDREN attribute, the value of which is used by HG_ROW_ID to show further results, when click the + sign.

    Now, the last level for a hierarchy would be the query where HG_HAS_CHILDREN is NULL. Generally, we set the HG_HAS_CHILDREN as NULL in the last query in UNION. If we can use a CASE statement in HG_HAS_CHILDREN that checks if there are any children for a given Object ID (Say, subprojects for a project), we can roll the hierarchy to the deepest level possible.

    Consider the below code (Just an Example for logic, may not apply to your condition):
    CASE 
                WHEN (SELECT COUNT(*) FROM inv_hierarchies h WHERE h.parent_id = INVp.ID) > 0 
    THEN 
                invp.id
    ELSE 
                NULL 
    END   HG_HAS_CHILDREN
    In the above code, what I am trying to do is roll the HG_HAS_CHILDREN, by checking whether the ID selected in INV_INVESTMENTS (alias - invp) has any children in INV_HIERARCHIES table. This should be included in the master query.

    In the second UNION query, instead of keeping the default NULL, use:
    CASE 
                 WHEN (SELECT COUNT(*) FROM inv_hierarchies h WHERE h.parent_id = INV.ID) > 0 
    THEN 
                @where:param:user_def:string:hg_row_id@
    ELSE NULL 
    END HG_HAS_CHILDREN
    This code would again loop the HG_HAS_CHILDREN and a magical "+" should appear on the child rows till NULL is returned by CASE statement for HG_HAS_CHILDREN.

    In short:

    The HG_ROW_ID = HG_HAS_CHILDREN value returned from Master query. If the HG_ROW_ID = NULL the + sign is not shown. If we keep the HG_HAS_CHILDREN rolling, a + would always be shown for all children till the level n.

    HTH

    ~Dev


  • 10.  Re: Multi Level Hierarchical Portlet

    Posted Oct 01, 2015 05:58 AM

    Hi,

     

    thanks for the tip.. but I'm not getting the 3rd level:

     

    LEVEL1 : PROGRAM

    LEVEL2: MASTER PROJECT

    LEVEL3: SubProjects and so on...

     

    see a quick NSQL to test:

     

     

    SELECT

    @SELECT:DIM:USER_DEF:IMPLIED:PROJECT:hgquery.name:name@,

    @SELECT:DIM_PROP:USER_DEF:IMPLIED:PROJECT:hgquery.parentid:parentid@,

    @SELECT:DIM_PROP:USER_DEF:IMPLIED:PROJECT:hgquery.Id:Id@,

    @SELECT:DIM_PROP:USER_DEF:IMPLIED:PROJECT:hgquery.inv_code:inv_code@,

    @SELECT:DIM_PROP:USER_DEF:IMPLIED:PROJECT:hgquery.hg_has_children:hg_has_children@

    FROM(

    -- PARENT (PROGRAM)

      select

      ip.name name,

      ip.id parentid,

      ip.id id,

      ip.code inv_code,

      ip.id hg_has_children

      from inv_investments ip

      inner join inv_projects p on p.prid = ip.id and p.is_program = 1

      group by

      ip.name ,

      ip.id ,

      ip.id ,

      ip.code ,

      ip.id

      having @where:param:user_def:integer:hg_row_id@ is null

    -- CHILDREN MASTER AND SUBPROJECTS

      union

      select

      ic.name name,

      ip.id parentid,

      ic.id id,

      ic.code inv_code,

    (CASE WHEN (SELECT COUNT(*) FROM inv_hierarchies h WHERE h.parent_id = ip.ID) > 0  THEN @where:param:user_def:integer:hg_row_id@ ELSE NULL END ) hg_has_children

      from inv_investments ip

      inner join inv_projects p on p.prid = ip.id and p.is_program = 1

      left outer join inv_hierarchies h on ip.id = h.parent_id

      left outer join inv_investments ic on h.child_id = ic.id

      where h.parent_id = @where:param:user_def:integer:hg_row_id@

    ) hgquery

    where 1=1 and @filter@

    group by

    name,

    parentid,

    id,

    inv_code,

    hg_has_children

     

    I get that:

     

    program - master looping.png

     

    Do i have to add a 3rd union? .. I tried to without success.

     

    What am I missing?



  • 11.  Re: Multi Level Hierarchical Portlet

    Posted Oct 01, 2015 06:18 AM


  • 12.  Re: Multi Level Hierarchical Portlet

    Posted Oct 01, 2015 06:32 AM

    perfect!! that solves my issue thx



  • 13.  Re: Multi Level Hierarchical Portlet

    Posted Oct 01, 2015 06:42 AM

    You're welcome, Aurora_Gaimon

     

    Would be great if you can share the final query

     

    NJ



  • 14.  Re: Multi Level Hierarchical Portlet

    Posted Oct 01, 2015 07:33 AM

    sure.. when I can figure out how to solve next issue.

     

    https://communities.ca.com/message/110409191#110409191

     

    it provides a hierarchy view specifically for Projects. When you have programs.. then my problem is .. all gets mixed on level 0 (single project, master projects, programs...)

    When expanding programs I see my hierarchy correctly:

     

    0) Program

    1) -- Master

       2) - Subproject1   

       2) - subproject2

    etc---

     

    I will have to re-think and re-work ... so far no success...because if I tried to add a new join to filter on INV_PROJECTS

     

    adding programs 1.png

     

     

    Results don't display as desired in NSQL. it will show just programs.. excluding everything under since those are projects...

     

    adding programs 2.png

     

     

    Need to spend some time working on this



  • 15.  Re: Multi Level Hierarchical Portlet

    Posted Oct 01, 2015 08:14 AM

    I managed.. not in a very elegant solution ... but it works:

     

    - I just want to see top level program... so I assinged program =1

    - tricking master.. also making it be program =1

    - and then children program 2

     

    so I add a filter in the query:

     

    and x.program in (1,2)

     

    So I dont see single projects or master projects (which are not in program) in level 0 and therefor program colum would be '0'

     

    adding programs 3.png



  • 16.  Re: Multi Level Hierarchical Portlet

    Posted Oct 01, 2015 10:18 AM

    too long looking the same.. I got a complicate solution when there is an easy and elegant one (@dummy me)

     

    and x.depth =0 and x.program =1

    OR  x.depth in (1,2) and  x.program =0

     

    I will publish query later.



  • 17.  Re: Multi Level Hierarchical Portlet

    Posted Oct 01, 2015 10:29 AM

    Thanks, Aurora

     

    NJ



  • 18.  Re: Multi Level Hierarchical Portlet

    Posted Oct 01, 2015 10:51 AM

    Aurora Gaimon wrote:

     

    too long looking the same.. I got a complicate solution when there is an easy and elegant one (@dummy me)

     

    and ((x.depth =0 and x.program =1)

    OR  (x.depth in (1,2) and  x.program =0))

     

    I will publish query later.

     

     

    Just be sure to group your conditions with brackets - I've guessed and inserted above where I suspect they should go.  Possibly overkill, but I tend to prefer explicitly setting rather than implicit because it makes it easier for future edits and understanding.

     

    Otherwise you may or may not get results at all since x.program can't be both 1 and 0 at the same time and you become too dependent on operator precedence to determine that outcome for you or an unfortunate bug introduced in a future edit when the query conditions get updated and shuffled around.



  • 19.  Re: Multi Level Hierarchical Portlet

    Posted Oct 01, 2015 11:12 AM

    thx, they are in my query.

    Now i'm buys rolling up figures.. making the "self" row appear too ...



  • 20.  Re: Multi Level Hierarchical Portlet

    Posted Oct 07, 2015 03:23 PM

    Finally achieved. I've coded from scratch:

     

    tree.png

     

    I could not use https://communities.ca.com/message/110409191#110409191

    when using the "self" row like the OOTB in the hierarchy tab in programs

    I need to rollup figures for each level and show the "self" too at instance level



  • 21.  Re: Multi Level Hierarchical Portlet

    Posted Feb 12, 2016 10:35 AM

    That looks fantastic, I've been struggling to create exactly what you've shown.  Would you be willing to share how you accomplished that?  I know this was a few months ago but I'm struggling to find a solid example of a 3 level hierarchy query, with self and roll up of dollars.



  • 22.  Re: Multi Level Hierarchical Portlet

    Broadcom Employee
    Posted Feb 12, 2016 04:04 PM

    Check out the PMO Accelerator portlet query 'Actuals by Transaction Type' (query ID = cop.trxTypeHierarchyLinkable)

    this has a hierarchical query and it is used on the Project Dashboard page.



  • 23.  Re: Multi Level Hierarchical Portlet

    Broadcom Employee
    Posted Oct 07, 2015 06:39 PM

    I am glad you were able to create the query.

    Additionally, here is a KB : it has a 'sample query'

     

    http://www.ca.com/us/support/ca-support-online/product-content/knowledgebase-articles/tec530394.aspx