on ‎2023 Jan 12 1:01 PM
Hi everyone!
We are trying to order the partitions of a table via scripting but we haven't succeeded yet. We found the problem when creating the record in the "Partitions" tab.
If we do it manually, the result is this:

However we don't know how to replicate that via scripting. Is it possible? Can anyone help us? At this moment this is our code:
Option Explicit
Dim mdl : set mdl = ActiveModel
Dim tbl, t , c ,objNewEC, objContent
dim havePartitions : havePartitions = false
set tbl = mdl.FindChildByCode("t_XXXXXXXXX",Cls_Table)
If tbl is nothing then
output "no se encontro la tabla"
Else
output "tbl.ExtendedCompositions.count=[" & tbl.ExtendedCompositions.count & "]"
If tbl.ExtendedCompositions.count > 0 then
set c = tbl.ExtendedCompositions.item(0)
output c.name
If strComp(c.name,"Partitions") = 0 then
havePartitions = true
End If
Else ' no hay ExtendedCompositions
havePartitions = false
output "Se crea la ExtendedCompositions para Partitions"
'set objNewEC = tbl.CreateObject(PdCommon.cls_ExtendedComposition)
set objNewEC = tbl.ExtendedCompositions.CreateNew
If not objNewEC is nothing then
objNewEC.name ="Partitions"
set objContent = objNewEC.Content.CreateNew
objContent.Name = "Partition_1"
objContent.Code = "Partition_1"
objContent.stereotype = "Partition"
Else
output "No se puede crear ExtendedCompositions"
End If
End If
End If ' si no encontro la tabla
With our code we only manage to create de partitions in the green part of the image but not the record in the partitions tab (red part of the image).

Thank you very much!!
Request clarification before answering.
Hello Ire,
your procedure of initializing ExtendedComposition is not valid. Instead you can use my code below and see how it works on screenshot attached.
You have to initialize only compositions that don`t currently exist. If the Partitions composition already exists in your table, you will be able to find it using simple For each... cycle too.
Dim t, kolekce, ec, part
For each t in Activemodel.Tables
output "Compositions Count = " + CStr(t.ExtendedCompositions.Count)
output "creating composition"
'Set kolekce = t.GetCollectionByName("Partitions") ' this initializes the composition if it doesn`t already exist in the table
For each ec in t.ExtendedCompositions
output ec.Name
Set part = ec.content.CreateNewAt(0, PdCommon.cls_ExtendedSubObject) ' this will put new partition to the top of the list
'Set part = ec.content.CreateNew(PdCommon.cls_ExtendedSubObject) ' this will put new partition to the bottom of the list
part.stereotype = "Partition"
output part.name
Next
output "Compositions Count = " + CStr(t.ExtendedCompositions.Count)
NextCreateNew or CreateNewAt methods could be used without any parameters when creating for example new column in a table. But when creating content of your "extended stuff", you have to specify objecttype (ExtendedSubObject) and don`t forget to specify Stereotype (Partition) too. See attached screenshot below.

HTH,
Ondrej Divis
P.S. Always add PD version to your questions. And in this particular case knowing which definition file you are using would be also useful. I used Hadoop Hive 2 for my screenshot-creating purposes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much ondrej_divis, that solved our problem!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 5 | |
| 5 | |
| 4 | |
| 4 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.