Book a Demo

Author Topic: Help changing Parent on an attribute from one class to another  (Read 19120 times)

ejafman

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Hi all,

Trying to automate (in vbscript) the movement of attributes from one Class to another.

On checking, I have found threads that say to just update the ParentID of the element to the new parent and refresh both the old and new parent.
Unfortunately, I am getting the error which says that I "Can't assign to read-only property".

Any clues?

TIA...Eric

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8107
  • Karma: +119/-20
    • View Profile
Re: Help changing Parent on an attribute from one class to another
« Reply #1 on: March 26, 2026, 02:33:21 pm »
Unfortunately, I am getting the error which says that I "Can't assign to read-only property".
Yep, it's marked as read-only in the documentation.

Attribute Class

I have found threads that say to just update the ParentID of the element to the new parent and refresh both the old and new parent.
It would appear that those threads either had people guessing, or they weren't about attributes. That process would work for child elements.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13510
  • Karma: +573/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Help changing Parent on an attribute from one class to another
« Reply #2 on: March 26, 2026, 05:49:21 pm »
If the property is read-only (why?) then the only solution is to go behind the API's back.

So update the Object_ID directly in the database, and then do an Element.Attributes.Refresh

There is an undocumented, and unsupported method called Repository.Execute(sqlStatement) in which you can pass an SQL update statement.
Obviously Eve can't give you that advice (since it's officially unsupported)

Geert

ejafman

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: Help changing Parent on an attribute from one class to another
« Reply #3 on: March 26, 2026, 08:55:53 pm »
Thanks...I was afraid of that.

Unfortunately, I do not have update rights in the actual DB itself, so don't think I could run an update SQL statement, I believe.

Thanks for the quick answers.

Eric

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13510
  • Karma: +573/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Help changing Parent on an attribute from one class to another
« Reply #4 on: March 27, 2026, 02:05:39 am »
Thanks...I was afraid of that.

Unfortunately, I do not have update rights in the actual DB itself, so don't think I could run an update SQL statement, I believe.

Thanks for the quick answers.

Eric
Repository.Execute uses the connection EA makes to the database.
If the user that EA uses has update rights it will work.

Geert

ejafman

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: Help changing Parent on an attribute from one class to another
« Reply #5 on: March 27, 2026, 10:31:55 pm »
good to know...I will see if that is possible.

Thanks

ejafman

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: Help changing Parent on an attribute from one class to another
« Reply #6 on: March 28, 2026, 12:12:28 am »
curious...if I do actually use the rep.execute method, should I still run a refresh on the old and new class? I am checking the data in the actual underlying tables, and actually don't see anything that would actually need refreshing.

UPDATE...I ran a test, and debugged. My actual hardcoded update statement did work, and then ran an update(),  and the Object_ID for the row in t_attribute flipped back to the original class.

Weird, or am I not getting it?

E
« Last Edit: March 28, 2026, 01:30:51 am by ejafman »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13510
  • Karma: +573/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Help changing Parent on an attribute from one class to another
« Reply #7 on: March 28, 2026, 02:18:01 am »
If you update the database, your object in memory don't know about that.
So if you have an attribute object in memory, and you call Update() it will save itself to the database, thereby overwriting the object_ID again.
So after doing a direct database updaate, you should consider your object in memory to be invalid.

Refreshing (element.Attributes.Refresh) reloads the attributes from the database.

Geert


ejafman

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: Help changing Parent on an attribute from one class to another
« Reply #8 on: March 28, 2026, 04:00:26 am »
Thanks for the tip...will play around ;)

Update: thanks again...me not running the update solved the problem
« Last Edit: March 28, 2026, 04:11:03 am by ejafman »