Author Topic: Creating a Custom Table via Script  (Read 1974 times)

EAButNotForGames

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Creating a Custom Table via Script
« on: July 16, 2024, 09:35:47 pm »
Moin,

Does anybody know if I can create a Custom Table with the dimensions x an y via a script.
I can create a dimensionless table. But not with rows and columns.
I figured, I need to set the TaggedValues data and dataFormat, but I can't change them via script.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13295
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating a Custom Table via Script
« Reply #1 on: July 16, 2024, 10:01:59 pm »
Why can't you change them with a script?

Can you show the code you are using?

Geert

EAButNotForGames

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: Creating a Custom Table via Script
« Reply #2 on: July 17, 2024, 03:32:58 pm »
So the code is basically:

Code: [Select]
var new_element as EA.Collection;
new_element = selectedPackage.Elements;

new_element = new_element.AddNew("A Table", "Custom Table");
new_element.TaggedValuesEx.GetAt(0).Notes = "Something"                    //This is the TaggedValue: data ->
new_element.TaggedValuesEx.GetAt(1).Notes = "Also Something"             //This is the TaggedValue: dataFormat -> They both have a specific format, but I was to lazy to type it

new_element.Update();

I tried both Value and Notes for TaggedValue and TaggedValueEx and it didn't work. 

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13295
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating a Custom Table via Script
« Reply #3 on: July 17, 2024, 04:07:05 pm »
You have to first get the tagged value object, then update it's value, and then save it to the database with .Update()

Element.Update() only saves the properties of the element to the database, not the properties of your tagged values.

Also, after creating an element you need to Update() it before it will have the tagged values you need.
And you'll want to create an element using the fully qualified stereotype. So something like "EAUML::Custom Table", making sure the stereotype exactly corresponds to the defined stereotype, inclusing upper/lower case.

Geert

EAButNotForGames

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: Creating a Custom Table via Script
« Reply #4 on: July 17, 2024, 09:10:24 pm »
Thank you very much!
This was such a simple mistake.

Also, do you by chance know, how I can access the Inital Value of a property?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13295
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating a Custom Table via Script
« Reply #5 on: July 17, 2024, 09:18:12 pm »
Also, do you by chance know, how I can access the Inital Value of a property?
You can't really. That value is defined in the MDG, and not stored in the database.

Geert

EAButNotForGames

  • EA User
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: Creating a Custom Table via Script
« Reply #6 on: July 17, 2024, 10:10:26 pm »
Ah, dam.