· Apr 8

DynaTree problem

Hi Guys,

Any Idea on how can make a dynaTree with 4 levels hierarchy (attached), I'm using the below code but sometimes works and other cases it doesn't?  

Set locId=..locId,pos=1,(pLineArr,astArr,compArr)=""
&Sql(Select Parent->Name,ID into :Fac,:kLoc from MSDS_COM.Loc where Parent=:locId)
Set:SQLCODE (Fac,kLoc)=""
Set pTree(0,"ch",1) = ""
Set pTree(1) = $LB(Fac,locId,1,"","")
Set Sql="Select ProductLine from MSDS_Serenity.ProdLineDetails where Active=1 and Loc="_kLoc_" group by ProductLine order by ID"
Set RS = ##class(%ResultSet).%New()
Do RS.Prepare(Sql)
Do RS.Execute()
While RS.Next(){
    Set pos=$I(pos)
    Set pLine = RS.GetData(1)
    Set pTree(1,"ch",pos) = ""
    Set pTree(pos) = $LB(pLine,pLine,1,"","")
    Set pLineArr=pLineArr_"|"_pLine
Set:$E(pLineArr,1)="|" $E(pLineArr,1)=""
Set pLen = $L(pLineArr,"|")
For i=1:1:pLen{
    Set Sql2 = "Select Asset->Name name,Asset from MSDS_Serenity.ProdLineDetails where Active=1 and Loc="_kLoc_" and %UPPER(ProductLine)='"_$ZCVT($P(pLineArr,"|",i),"U")_"' group by Asset->Name order by ProductLine"
    Set RS2 = ##class(%ResultSet).%New()
    Do RS2.Prepare(Sql2)
    Do RS2.Execute()
    s level=$I(Level)
    While RS2.Next(){
        Set pos = $I(pos)
        Set Asset = RS2.GetData(1)
        Set aID = RS2.GetData(2)
        Set pTree(i+1,"ch",pos) = ""
        Set pTree(pos) = $LB(Asset,aID,1,"","")
        Set astArr=astArr_"|"_Asset
        Set ^Tree("Asset",pos)=Asset_"|"_level
Set:$E(astArr,1)="|" $E(astArr,1)=""
Set aLen = $L(astArr,"|")
Set ^Tree("aLen")=astArr_"|"_aLen
For j=1:1:aLen{
    Set Sql3 = "Select Component->Name,Component from MSDS_Serenity.ProdLineDetails where Active=1 and Loc="_kLoc_" and %UPPER(Asset->name)='"_$P(astArr,"|",j)_"' order by Asset"
    &SQL(Select count(Component->Name) into:Component from MSDS_Serenity.ProdLineDetails where Active=1 and Loc=:kLoc order by Asset)
    Set RS3 = ##class(%ResultSet).%New()
    Do RS3.Prepare(Sql3)
    Do RS3.Execute()
    s level=$I(Level)
    While RS3.Next(){
        Set pos = $I(pos)
        Set Comp = RS3.GetData(1)
        Set cID = RS3.GetData(2)
        Set pTree(j+aLen,"ch",pos) = ""
        Set pTree(pos) = $LB(Comp,cID,1,"","")
        Set compArr=compArr_"|"_cID
Set:$E(compArr,1)="|" $E(compArr,1)=""
Set cLen = $L(compArr,"|")
s level=aLen+cLen-1 For k=1:1:cLen{
Set Sql4="Select MSDS_UI_HandHeld_RTLSLogin.Inventory_getLabel(ChildKitInst->Beacon) as Label from MSDS_Serenity.KitContent where KitId="_$P(compArr,"|",k)_" and MSDS_UI_HandHeld_RTLSLogin.Inventory_getLabel(ChildKitInst->Beacon) is not null order by Label"
Set RS4 = ##class(%ResultSet).%New()
Do RS4.Prepare(Sql4)
Do RS4.Execute()
While RS4.Next(){
    Set pos = $I(pos)
    Set Label = RS4.GetData(1)
    Set pTree(level+k,"ch",pos) = ""
    Set pTree(pos) = $LB(Label,Label,0,"","")



Product version: Ensemble 2018.1
Discussion (1)1
Log in or sign up to continue