cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Build an Organizational Chart in HOPEX programmatically

simikadampatta
Trusted Contributor

Hello,

We are consuming an API using Java to populate Org-Unit details like the Org-Unit Manager and respective Sub-Org Units. The client wants to build the complete Organizational Chart programmatically using the data populated. 

Kindly share your suggestions.

5 Replies

Thank you very much, it worked like a charm. However, I would like to control the drawing layout in detail in terms of creating the links as needed.

Can you advise me on getting the actual code for this Java macro?  "OrgChartLayoutImplementation"

 

Hi @rizwanghafoor

you can try the following like the following (note : I think that depending on the version you are using, you may need to cast the abstract description link to avoid a warning, this could be made more robust but should work)
Sub AddSubOrgUnits(ou, Diag)
'this gets ALL the subs org-units of the root org unit in parameter - replace by a query retrieving the required depth

getRoot.Print("processing org " & ou.getProp("~Z20000000D60[Short Name]"))

Dim subs
Dim temp
temp= "Select [Org-unit] Where [Aggregation of].[short Name] Deeply like " & "'" & ou.getProp("~Z20000000D60[Short Name]") & "'" & " "
'getRoot.Print(temp)
set subs = getRoot.getSelection(temp)

'this opens the drawing of the diagram in parameter in read write mode

Dim Org
Dim Drawing
Set Drawing = Diag.Drawing("RW")

'this adds the sub org units in the diagram

For each Org in subs
Drawing.MegaObjectInsert(Org)
'getRoot.Print("org " & Org.getProp("~Z20000000D60[Short Name]") & " has been added to diagram " & Diag.getProp("~Z20000000D60[Short Name]"))
Drawing.Flush
Next

'this triggers the hierarchical layout computation. This will throw an error if the diagram is too large

Dim mgobjMacro
Set mgobjMacro = getRoot.CurrentEnvironment.GetMacro("~A1mFy(3SMniV[OrgChartLayoutImplementation]")
mgobjMacro.OnLoadDrawing Drawing
Drawing.Flush

End Sub

'this sample code get all root org units (with no parents, with components), creates an org chart and adds the root org uit on its org chart, and then calls the function above to add sub org units

Dim RootOrgUnits
Set RootOrgUnits = getRoot.getSelection("Select [Org-unit] Where [Aggregation of] null and [Component] not null")
Dim MyOu

For Each MyOu in RootOrgUnits
Set colDescription = MyOu.GetCollection("Description")
Set oNewDiagram = colDescription.Add("'" & MyOu.getProp("~Z20000000D60[Short Name]") & "'" & " test org chart")
oNewDiagram.GetProp("Nature") = "ORGANIGRAMME"
Dim Drawing
Set Drawing = oNewDiagram.Drawing("RW")
Drawing.MegaObjectInsert(MyOu)
Drawing.Flush
AddSubOrgUnits MyOu, oNewDiagram
Next

 

rizwanghafoor
MEGA Partner
MEGA Partner

Hi,

@OLeGuellec Can you please guide the steps to create this diagram(Organizational Chart) automatically?

Thank you for the reply.

I am able to do so through the UI, but can I automatically initialize the diagrams using Java without having to manually initialize it for each Org-Unit?

If yes, how can I do that?

 

Kindly share any available documentation.

OLeGuellec
MEGA
MEGA

Hi,

In the UI, the diagram initialization automatically populates the diagram with the described object components, and a hierarchical layout reorganization is provided 

 

it should be possible to do the same via the API.

 

OLeGuellec_0-1679480093204.png