design studio dynamic hierarchy

8
Getting Started Newsletters Store Products Services & Support About SCN Downloads Industries Training & Education Partnership Developer Center Lines of Business University Alliances Events & Webinars Innovation Log On Join Us Hi, Guest Search the Community Activity Communications Actions Browse SAP BusinessObjects Design Studio Tweet Introduction In this edition of the Design Studio Innovation Series, I'm going to describe an approach for implementing a hierarchy filter based on standard and SDK Development Community components, to take advantage of complementary features of both. With the standard functionality, we can implement cascading filters with the Dropdown Box and List Box components but neither of these cater for hierarchy structures, which is the requirement I will address here. The Result The solution allows compact, levelbylevel hierarchical drilldown, with the option to drill back up levelby level or go straight to the beginning. Before going into the details, here's the end result in the form of an animated gif (Click on the image if it doesn't start playing immediately. It may take a little bit of time to load). In this example, the hierarchy filter is driving a chart: For those of you who want to get straight to it, a sample BIAPP is attached at the end. For those interested in the details, read on!... Background This post was inspired by the Cascade Filter for Hierarchy Dimension question from Oscar Olivares Pous. Since the requirement involved a fixed level hierarchy structure, I was able to propose a solution that relied only on standard functionality based on the Crosstab component. A further thought then occurred to me about how could the solution be extended to achieve dynamic filtering for drilling down and up a hierarchy structure with many levels of varying depth, as shown below?: Design Studio Innovation Series Topic 5: A Best of Both Worlds Implementing a Dynamic Hierarchy Filter by combining Standard and SDK Community Components Posted by Mustafa Bensan in SAP BusinessObjects Design Studio on May 25, 2015 1:31:57 PM 1 Like

Upload: dong-hai-nguyen

Post on 15-Sep-2015

28 views

Category:

Documents


0 download

DESCRIPTION

Design Studio Dynamic Hierarchy

TRANSCRIPT

  • 17/6/2015 DesignStudioInnovationSeriesTopic5:ABe...|SCN

    http://scn.sap.com/community/businessobjectsdesignstudio/blog/2015/05/25/designstudioinnovationseriestopic5implementingahierarchyfilterwit 1/8

    GettingStarted Newsletters Store

    Products Services&Support AboutSCN Downloads

    Industries Training&Education Partnership DeveloperCenter

    LinesofBusiness UniversityAlliances Events&Webinars Innovation

    LogOn JoinUsHi,Guest SearchtheCommunity

    Activity Communications Actions

    Browse

    SAPBusinessObjectsDesignStudio

    Tweet

    IntroductionInthiseditionofthe DesignStudioInnovationSeries,I'mgoingtodescribeanapproachforimplementingahierarchyfilterbasedonstandardand SDKDevelopmentCommunitycomponents,totakeadvantageofcomplementaryfeaturesofboth.Withthestandardfunctionality,wecanimplementcascadingfilterswiththeDropdownBoxandListBoxcomponentsbutneitherofthesecaterforhierarchystructures,whichistherequirementIwilladdresshere.TheResultThesolutionallowscompact,levelbylevelhierarchicaldrilldown,withtheoptiontodrillbackuplevelbylevelorgostraighttothebeginning.Beforegoingintothedetails,here'stheendresultintheformofananimatedgif(Clickontheimageifitdoesn'tstartplayingimmediately.Itmaytakealittlebitoftimetoload).Inthisexample,thehierarchyfilterisdrivingachart:

    Forthoseofyouwhowanttogetstraighttoit,asampleBIAPPisattachedattheend.Forthoseinterestedinthedetails,readon!...BackgroundThispostwasinspiredbythe CascadeFilterforHierarchyDimensionquestionfrom OscarOlivaresPous.Sincetherequirementinvolvedafixedlevelhierarchystructure,IwasabletoproposeasolutionthatreliedonlyonstandardfunctionalitybasedontheCrosstabcomponent.Afurtherthoughtthenoccurredtomeabouthowcouldthesolutionbeextendedtoachievedynamicfilteringfordrillingdownandupahierarchystructurewithmanylevelsofvaryingdepth,asshownbelow?:

    DesignStudioInnovationSeriesTopic5:ABestofBothWorldsImplementingaDynamicHierarchyFilterbycombiningStandardandSDKCommunityComponentsPostedbyMustafaBensaninSAPBusinessObjectsDesignStudioonMay25,20151:31:57PM

    1Like

  • 17/6/2015 DesignStudioInnovationSeriesTopic5:ABe...|SCN

    http://scn.sap.com/community/businessobjectsdesignstudio/blog/2015/05/25/designstudioinnovationseriestopic5implementingahierarchyfilterwit 2/8

    WecouldcertainlyuseaCrosstabcomponentasis,asshownabovebutthiscanbecomeunwieldyasnodesareexpandedandcollapsed,withtheaddedneedforscrollingwhenthestructureislarge.Similarly,useofthestandardDimensionFilteralsorequiresnodemanipulationandscrolling,withseveralclickstofindtherequireditemandthenbackouttoapply,asshownbelow:

    TheApproach

    ThesolutioniscentredaroundastandardCrosstabcomponentbecauseunliketheDropdownBoxandListBox,itsupportsdisplayofahierarchystructureandselectionofnodes.DrillingdownahierarchyonelevelatatimebyapplyingthesetFilter()methodonthedatasourceassignedtoaCrosstabisrelativelystraightforward.However,theproblemariseswhenweneedtoimplementdrillupfunctionalitytomovebackinthehierarchy.Theproblemhereisweneedtosomehow"remember"thedrillpathandparentchildrelationships.AsfarasIcouldsee,therewasnoeasywaytoachievethiswithstandardscriptingalone.Weneedtostorethedrillpathinsomekindofstructurethatwecanmanipulateandlookup,soItookalookatthe DesignStudioSDK:CollectionUtilityComponentfromthe

    SDKDevelopmentCommunityasapossiblecandidateanditdidthetrick!Note:TheCollectionUtilitycomponentcurrentlydoesn'tseemtoallowdeletionofspecificentriessoalldrillpathsthattheusertraversesarestoredthefirsttimetheusergoesdownaparticularpath.Ithinkagreatenhancementtothe

    DesignStudioSDK:CollectionUtilityComponentwouldbesupportforstackfunctionalitywithPushandPopmethods.Thiswouldallowamoreefficientmechanismforrecordingandtraversingdrillpathsandonlythecurrentdrillpathwouldneedtobetracked.Sonowlet'sgothroughastepbystepbreakdown.DataSourceInordertoallowlevelbyleveldrilldown,theInitialViewofthemaindatasourceisconfiguredasshownbelow,expandedtolevel2:

  • 17/6/2015 DesignStudioInnovationSeriesTopic5:ABe...|SCN

    http://scn.sap.com/community/businessobjectsdesignstudio/blog/2015/05/25/designstudioinnovationseriestopic5implementingahierarchyfilterwit 3/8

    ComponentsMyaimwastoimplementamodular,reusablesolution,soontheUIsideIhaveeffectivelycreatedacompositecomponentbycombiningaHomeButton,BackButtonandCrosstabwithinaPanelcomponent:

    Intheoutlinepanelitlookslikethis:

    Totrackthedrillpath,IhaveIhaveusedtwocollectionsimplementedwiththe DesignStudioSDK:CollectionUtilityComponent:

    TheHierarchycollectionkeepstrackofthedrillpathandtheVariablecollectiontracksthepreviousnodetoallowreversalbackupthedrillpath.IprobablycouldhaveusedaGlobalScriptVariabletoperformthesamefunctionastheVariablecollectionbutthoughtitwouldhelpmakethesolutionalittlemoremodular.FordemopurposesI'vealsoincludedtheSDKDevelopmentCommunity FioriAppHeadercomponent.CSSIhaveadapted HaripriyaGopi'sveryusefulmethodfor DefaultSelectioninaCrosstabtoimplementthefollowingfunctionality:

    1. Highlightthefirstrowasthedefaultselectiononstartup2. Highlightthefirstrowasthedefaultselectionwhendrillingbacktothepreviouslevel

    TheCSSfilefortheapplicationhasbeennameddefaultselection.cssandconsistsofthefollowingcode:

    TheCSSfileshouldbeassignedtotheApplicationPropertiesasshownbelow:

    01. .highlightrow.sapzencrosstabRowHeaderAreatr:nthchild(1).sapzencrosstabHeaderRowtd:nthchild(1)02. {03. backgroundcolor:#7bc3ef!important04. }

  • 17/6/2015 DesignStudioInnovationSeriesTopic5:ABe...|SCN

    http://scn.sap.com/community/businessobjectsdesignstudio/blog/2015/05/25/designstudioinnovationseriestopic5implementingahierarchyfilterwit 4/8

    TheCSSClasshighlightrowshouldthenbeassignedtotheCrosstabcomponentasshownbelow:

    GlobalScriptVariablesIhavedefinedasetofconstantsasGlobalScriptVariablessotheycanbemaintainedcentrally,asshownbelow:

    GlobalScriptFunctionsTokeepthecodemodular,severalscriptfunctionshavebeencreatedundertheHIERARCHY_FILTERglobalscriptsobjectasshownbelow:

  • 17/6/2015 DesignStudioInnovationSeriesTopic5:ABe...|SCN

    http://scn.sap.com/community/businessobjectsdesignstudio/blog/2015/05/25/designstudioinnovationseriestopic5implementingahierarchyfilterwit 5/8

    Eachofthesefunctionsareselfcontainedinthatallnecessaryexternaldataarepassedasinputparameters.Agreatfeatureofglobalscriptfunctionsisthatyoucanevenpassincomponentsanddatasourcesasparametersandthenperformactionsonthesesuchassettingpropertiesorfiltering,soyoucanapplythesamestandardprocesstomultiplecomponents/datasourcesifneeded.I'llnowdescribeeachofthefunctionsinlogicalorder.initialize:Thisfunctioniscalledfromthe"OnStartup"eventscriptoftheapplication.Itperformsthefollowingmaintasks:

    VerifiesthatthedimensionwewanttodrillonhasanactivehierarchyassignedtoitInitializesthecollectionsforthehierarchystructureandpreviousnodeSetsthedefaulttextofthefiltervalueDisablesnavigation,sortingandcolumnresizingonthefiltercrosstabDisablesthebackbutton

    Itrequiresthefollowingparameters:

    InputParameter Type Description

    pCrosstab Crosstab Crosstabforhierarchyfilter

    pHierarchyDimension String Dimensionforhierarchyfilter

    pHierarchyRoot String Rootofhierarchy

    pHierarchyRootDescription String Hierarchyrootdescription

    pHierarchyPrefix String Hierarchyprefix

    pDataSource DataSourceAlias DataSourceforhierarchyfilter

    pHierarchyCollection org.scn.community.utils.Collection Collectionforhierarchy

    pVariableCollection org.scn.community.utils.Collection Variablecollectionforhierarchy

    pBackButton Button BackButton

    pTitleText Text SelectedItemText

    pPreviousNodeID String PreviousNodeIdentifierkeyusedinvariablecollectionlookup

    Thescriptiscodedasfollows:

    drillDown:Thisfunctioniscalledfromthe"OnSelect"eventscriptofthefiltercrosstab.Itistheengineofoverallfunctionalityandperformsthefollowingmaintasks:

    InitializesvariablesRecordsthedrillpathDrillsdowntothenextlevelAppliesafiltertothetargetdatasource

    Itrequiresthefollowingparameters:

    InputParameter Type Description

    01. //02. //InitialiseHierarchyFilter03. //04. //Verifyactivehierarchiesexist05. if(!pDataSource.isHierarchyActive(pHierarchyDimension))06. {07. APPLICATION.createErrorMessage("Noactivehierarchyfordatasource"+pDataSource.getInfo().dataSourceName)08. returnfalse09. }10. //InitializeCollections11. varhierarchyRoot=pHierarchyPrefix+pHierarchyRoot12. pHierarchyCollection.addItem(hierarchyRoot,'',0.0,pHierarchyRootDescription)//Initializefirstindexitemwithhierarchyrootnode13. pVariableCollection.addItem(pPreviousNodeID,hierarchyRoot,0.0,pHierarchyRootDescription)//Initializepreviouslyselectednode14. //Setrootnodedescriptionasdefaulttext15. pTitleText.setText(pHierarchyCollection.getEntryByKey(hierarchyRoot).prop1)16. //Initialisecrosstabsettings17. pCrosstab.setHierarchyNavigationEnabled(false)//Disablenavigation18. pCrosstab.setSortingEnabled(false)//Disablesorting19. pCrosstab.setColumnResizingEnabled(false)//Disablecolumnresizing20. pBackButton.setEnabled(false)//DisableBackbutton21. returntrue

  • 17/6/2015 DesignStudioInnovationSeriesTopic5:ABe...|SCN

    http://scn.sap.com/community/businessobjectsdesignstudio/blog/2015/05/25/designstudioinnovationseriestopic5implementingahierarchyfilterwit 6/8

    pCrosstab Crosstab Crosstabforhierarchyfilter

    pHierarchyDimension String Dimensionforhierarchyfilter

    pDataSource DataSourceAlias Hierarchydatasource

    pTargetDataSource DataSourceAlias Targetdatasourceforfiltering

    pHierarchyCollection org.scn.community.utils.Collection Collectionforhierarchy

    pVariableCollection org.scn.community.utils.Collection Variablecollectionforhierarchy

    pBackButton Button BackButton

    pHierarchyNodePrefix String Hierarchynodeprefix

    pPreviousNodeID String PreviousnodeIDforvariablecollectionlookup

    pNotApplicable String NotApplicableconstantvalue

    pAllMembers String Allmembersfiltervalue

    Thescriptiscodedasfollows:

    filterTarget:ThisfunctioniscalledfromthedrillDown,backandhomefunctions.Itperformsthefollowingmaintasks:

    FiltersthetargetdatasourceUpdatesthetextfieldtodisplaythenewfiltervalue

    Itrequiresthefollowingparameters:

    InputParameter Type Description

    pDataSource DataSourceAlias Targetdatasourceforapplyingfilter

    pFilterDimension String Dimensiontobefilteredintargetdatasource

    pFilterKey String Dimensionmemberkeytobefilteredintargetdatasource

    pFilterText String Dimensionmembertext

    pText Text Textcomponenttodisplayselecteddimensionmember

    Thescriptiscodedasfollows:

    back:

    01. //02. //DrilldownProcessing03. //CalledfromOnSelecteventofCrosstab04. //05. //Initialisevariables06. varparentNodeKey=""07. varselectedFilterKey=pCrosstab.getSelectedMember(pDrillDimension).internalKey08. varselectedFilterText=pCrosstab.getSelectedMember(pDrillDimension).text09. varindexCheck=pHierarchyCollection.getIndexByKey(selectedFilterKey)+''10. varnodePrefix=selectedFilterKey.substring(0,pHierarchyNodePrefix.length)11. varpreviousNodeKey=pVariableCollection.getLabelByKey(pPreviousNodeID)12. varrootNode=pHierarchyCollection.getKeyByIndex(0)13. //Adddrillpathtocollectiononlyifithasnotalreadybeenaddedfromapreviousdrilldown14. if(indexCheck==pNotApplicable&&selectedFilterKey!=pAllMembers&&nodePrefix==pHierarchyNodePrefix)15. {16. parentNodeKey=previousNodeKey17. pHierarchyCollection.addItem(selectedFilterKey,parentNodeKey,0.0,selectedFilterText)18. }19. //Drilldowntothenextlevelonlyiftheselectednodeisahierarchynode20. //Updatepreviousnode21. if(nodePrefix==pHierarchyNodePrefix)22. {23. pDataSource.setFilter(pDrillDimension,selectedFilterKey)24. pVariableCollection.removeAllItems()25. pVariableCollection.addItem(pPreviousNodeID,selectedFilterKey,0.0,selectedFilterText)26. }27. else28. {29. pCrosstab.setCSSClass("")//Clearfirstrowhighlightingifselectionisleafnode30. }31. //IftheBackbuttonisnotenabledthenenableitifconditionsaremet32. if(!pBackButton.isEnabled()&&selectedFilterKey!=pAllMembers&&selectedFilterKey!=rootNode)33. {34. pBackButton.setEnabled(true)35. }36. //Applyfiltertothetargetiffilterisnot"allmembers"37. if(selectedFilterKey!=pAllMembers)38. {39. HIERARCHY_FILTER.filterTarget(pTargetDataSource,pDrillDimension,selectedFilterKey,selectedFilterText,TEXT_CHART_TITLE)40. }

    01. //02. //FilterTarget03. //04. pDataSource.setFilter(pFilterDimension,pFilterKey)05. pText.setText(pFilterText)//Updatetexttodisplaynewfiltervalue

  • 17/6/2015 DesignStudioInnovationSeriesTopic5:ABe...|SCN

    http://scn.sap.com/community/businessobjectsdesignstudio/blog/2015/05/25/designstudioinnovationseriestopic5implementingahierarchyfilterwit 7/8

    Thisfunctioniscalledfromthe"OnClick"eventscriptoftheBackbutton.Itperformsthefollowingmaintasks:

    InitializesvariablesUpdatestheprevioushierarchynodeDrillsbacktotheprevioushierarchynodeAppliesafiltertothetargetdatasource

    Itrequiresthefollowingparameters:

    InputParameter Type Description

    pDataSource DataSourceAlias Hierarchydatasource

    pTargetDataSource DataSourceAlias Targetdatasourceforfiltering

    pHierarchyCollection org.scn.community.utils.Collection Collectionforhierarchy

    pVariableCollection org.scn.community.utils.Collection Variablecollectionforhierarchy

    pBackButton Button BackButton

    pText Text TextcomponenttodisplayselecteddimensionmemberpHierarchyDimension String DimensionforHierarchyFilter

    pPreviousNodeID String PreviousnodeIDforvariablecollectionlookuppCrossTab Crosstab CrosstabforHierarchyFilter

    pRowSelectionClass String CSSClasstohighlightfirstrowofcrosstab

    Thescriptiscodedasfollows:

    home:

    Thisfunctioniscalledfromthe"OnClick"eventscriptoftheHomebutton.Itperformsthefollowingmaintasks:

    GetstherootnodeofthehierarchyResetstheprevioushierarchynodeRemovesthehierarchyfilterFiltersthetargetdatasourcebasedontherootnode

    Itrequiresthefollowingparameters:

    InputParameter Type Description

    pDataSource DataSourceAlias Hierarchydatasource

    pTargetDataSource DataSourceAlias Targetdatasourceforfiltering

    pHierarchyCollection org.scn.community.utils.Collection Collectionforhierarchy

    pVariableCollection org.scn.community.utils.Collection Variablecollectionforhierarchy

    pBackButton Button BackButton

    pHierarchyDimension String DimensionforHierarchyFilter

    pPreviousNodeID String PreviousnodeIDforvariablecollectionlookuppCrossTab Crosstab CrosstabforHierarchyFilter

    pRowSelectionClass String CSSClasstohighlightfirstrowofcrosstab

    01. //02. //Backbutton(drillup)Processing03. //04. //InitialiseVariables05. varpreviousNode=pVariableCollection.getLabelByKey(pPreviousNodeID)06. varparentNode=pHierarchyCollection.getLabelByKey(previousNode)07. varparentNodeText=pHierarchyCollection.getEntryByKey(parentNode).prop108. varrootNode=pHierarchyCollection.getKeyByIndex(0)09. previousNode=parentNode10. varpreviousNodeText=parentNodeText11. //UpdatePreviousNode12. pVariableCollection.removeAllItems()13. pVariableCollection.addItem(pPreviousNodeID,previousNode,0.0,previousNodeText)14. //Setfiltertodrillbacktopreviousnode(parentnode)15. pDataSource.setFilter(pHierarchyDimension,previousNode)16. //Applyhighlighttofirstrowofcrosstab17. pCrossTab.removeSelection()18. pCrossTab.setCSSClass(pRowSelectionClass)19. //DisableBackbuttoniftopofhierarchyhasbeenreached20. if(previousNode==rootNode)21. {22. pBackButton.setEnabled(false)23. }24. //Applyfiltertotargetdatasource25. HIERARCHY_FILTER.filterTarget(pTargetDataSource,pHierarchyDimension,previousNode,previousNodeText,pText)

  • 17/6/2015 DesignStudioInnovationSeriesTopic5:ABe...|SCN

    http://scn.sap.com/community/businessobjectsdesignstudio/blog/2015/05/25/designstudioinnovationseriestopic5implementingahierarchyfilterwit 8/8

    FollowSCNSiteIndex ContactUs SAPHelpPortalPrivacy TermsofUse LegalDisclosure Copyright

    AverageUserRating

    (3ratings)

    Tweet

    Thescriptiscodedasfollows:

    StartupScript:

    ComponentScripts:

    Crosstab:

    HomeButton:

    BackButton:

    Conclusion

    Ihopethehierarchyfilterapproachdescribedhereisusefulforthoseofyouwhohavesucharequirement.TheBIAPPintheanimateddemoaboveisattached.Commentsandquestionsarewelcomeasalways.Enjoy.BlogSeriesIndex: DesignStudioInnovationSeriesWelcome

    600Views Categories:SDK,Scripting,BW,HANA Tags:sapzen,design_studio,design_studio_sdk

    01. //02. //HomeButtonProcessing03. //04. //Getrootnodeinformation05. varrootNodeKey=pHierarchyCollection.getKeyByIndex(0)06. varrootNodeText=pHierarchyCollection.getEntryByKey(rootNodeKey).prop107. //Resetpreviousnodepointer08. pVariableCollection.removeAllItems()09. pVariableCollection.addItem(pPreviousNodeID,rootNodeKey,0.0)10. //Removefiltertoresethierarchytotoplevel11. pDataSource.clearFilter(pHierarchyDimension)12. //Removepreviousrowselectionandhighlightfirstrowasdefault13. pCrossTab.removeSelection()14. pCrossTab.setCSSClass(pRowSelectionClass)15. //DisableBackbutton16. pBackButton.setEnabled(false)17. //Filtertargetdatasourcebasedonrootnode18. HIERARCHY_FILTER.filterTarget(pTargetDataSource,pHierarchyDimension,rootNodeKey,rootNodeText,TEXT_CHART_TITLE)

    01. HIERARCHY_FILTER.initialize(CROSSTAB_FILTER,cDrillDimension,cHierarchyRootNode,cHierarchyRootNodeDesc,cHierarchyPrefix,DS_1,HIERARCHY_COLLECTION,VARIABLE_COLLECTION,BACK_BUTTON,TEXT_CHART_TITLE,cPreviousNode)

    01. HIERARCHY_FILTER.drillDown(CROSSTAB_FILTER,cDrillDimension,DS_1,DS_2,HIERARCHY_COLLECTION,VARIABLE_COLLECTION,BACK_BUTTierarchyNodePrefix,cPreviousNode,cNotApplicable,cAllMembers)

    01. HIERARCHY_FILTER.back(DS_1,DS_2,HIERARCHY_COLLECTION,VARIABLE_COLLECTION,BACK_BUTTON,TEXT_CHART_TITLE,cDrillDimension,cPre

    01. HIERARCHY_FILTER.back(DS_1,DS_2,HIERARCHY_COLLECTION,VARIABLE_COLLECTION,BACK_BUTTON,TEXT_CHART_TITLE,cDrillDimension,cPrviousNode,CROSSTAB_FILTER,cRowSelectionClass)

    SCN_BLOG_HIERARCHY_FILTER_DEMO.zip.txt.zip(5.5K)

    1Like

    Therearenocommentsonthispost

    0Comments