Book a Demo

Author Topic: Update is not a function  (Read 7394 times)

Wojtas

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
Update is not a function
« on: March 30, 2015, 09:10:49 pm »
Hi,

I'm writing script that synchronize TVs between elements. When I try to Update TaggedValues collection after AddNew this error is thrown.
By the way, all scripts that operate on collection stop working. I don't remember is this related to last EA upgrade (can't recall when I upgrade EA), but I guess that it is connected.
Any ideas?

Kind regards,
Wojtek

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Update is not a function
« Reply #1 on: March 30, 2015, 10:03:20 pm »
Post some of your code and indicate where it throws an error.

Geert

Wojtas

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
Re: Update is not a function
« Reply #2 on: March 30, 2015, 10:34:57 pm »
Code: [Select]
var theElement as EA.Element;
theElement = Repository.GetTreeSelectedObject();
var tvs as EA.Collection;
tvs = theElement.TaggedValues;
var klasa = Session.Input("Enter class of TV, eg.:\"System\"");
var regExp = new RegExp("^"+klasa);
var pt = Repository.PropertyTypes;
var ptc = pt.Count;
for(var i=0;i<ptc;i++)
{
      var TV = pt.GetAt(i);
      if(tvs.GetLastError())
            Session.Output("Global Error:"+tvs.GetLastError());
      if(TV.Tag.search(regExp)>=0 && !tvs.GetByName(TV.Tag))
      {
            Session.Output(TV.Tag);
            var tvsr = tvs.AddNew(TV.Tag,"");
            var updt = tvs.Update();
      }
}
var updt = tvs.Update(); generate problem.

Kind regards,
Wojtek
« Last Edit: March 30, 2015, 10:36:06 pm by wkrolik »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Update is not a function
« Reply #3 on: March 30, 2015, 11:04:10 pm »
You can not update the collection. You can call update only on newly generated elements/connectors/... Maybe you mean refresh(), but that's superfluous in most cases.

q.
« Last Edit: March 30, 2015, 11:04:49 pm by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Update is not a function
« Reply #4 on: March 30, 2015, 11:06:28 pm »
Why would you try to call Update() on an EA.Collection?
I don't think this has ever existed.
You call Update() on the individual objects, not on collections.

The only thing you sometimes need on a collection is Refresh(), but most often you don't even need that.

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Update is not a function
« Reply #5 on: March 30, 2015, 11:07:37 pm »
Quote
You can not update the collection. You can call update only on newly generated elements/connectors/... Maybe you mean refresh(), but that's superfluous in most cases.

q.

Good to see we are on the same page on this  :)

Geert

Wojtas

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
Re: Update is not a function
« Reply #6 on: March 30, 2015, 11:38:19 pm »
Hi,

can't agree with you. For example collection EmbeddedElements can be extended by new elements. Used last week and this is existing collection as well. Why Tagged Value collection is ineditable (was accessible - 100% sure - I was adding TVs (30 newly defined) to ~80 component elements) and Embedded Elements collection is editable?
@Geert: AddNew and Update functions are defined on EA site:
http://www.sparxsystems.com/enterprise_architect_user_guide/12/automation_and_scripting/collection.html
Calling of Update is advised in AddNew function description.
var tvs as EA.Collection;
tvs = theElement.TaggedValues; - declares variable before use, I wrote this "hoping" that help, but didn't  :(
var tvs = theElement.TaggedValue; got back to this version, only thing that changed is that "Ctrl+Space" stop working - EA can't determine type of variable.
Continue digging :S

Kind regards,
Wojtek

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Update is not a function
« Reply #7 on: March 30, 2015, 11:51:10 pm »
Well, two statements from experienced EA users against one from a rookie. That sounds like a good base for discussions.

q.

Wojtas

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
Re: Update is not a function
« Reply #8 on: March 31, 2015, 12:03:01 am »
SOLVED  ;D

Update function should be invoked on result element, not collection :D
Walked by old working script and found this difference.
Working code:
Code: [Select]
var theElement as EA.Element;
theElement = Repository.GetTreeSelectedObject();
var tvs as EA.Collection;
tvs = theElement.TaggedValues;
Session.Output(theElement.Name+" "+theElement.Stereotype+" "+theElement.ElementGUID);
var klasa = Session.Input("Podaj klas[ch281] TV, np.:\"System\"");
var regExp = new RegExp("^"+klasa);
var pt = Repository.PropertyTypes;
var ptc = pt.Count;
for(var i=0;i<ptc;i++)
{
      var TV = pt.GetAt(i);
      if(tvs.GetLastError())
            Session.Output("Global Error:"+tvs.GetLastError());
      if(TV.Tag.search(regExp)>=0 && !tvs.GetByName(TV.Tag))
      {
            Session.Output(TV.Tag);
            var tvsr = tvs.AddNew(TV.Tag,"");
            tvsr.Update();
      }
}            
break;
I have to change way I'm naming variables - tvs (for TaggedValueS) and tvsr (for TaggedValueSResult) are too easy to misstype.
Also on site with collection reference is stated:
Quote
Call Update on the item to save it to the database
Quote
Also note that you must call Update() on the returned object to complete the AddNew. If Update() is not called the object is left in an indeterminate state.

Have a nice day,
Wojtek
« Last Edit: March 31, 2015, 12:07:18 am by wkrolik »

Echo

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Update is not a function
« Reply #9 on: March 08, 2019, 10:03:55 pm »
Hi,

Anyone has idea how to delete these "indeterminate" Status objects? :'( :'(

Same mistake I did, did not call Update function after AddNew. Then I can see this object I created in "Find in Project" view, but I cannot locate it in the ProjectBrowser. I tried to delete it directly in the "Find in Project" view, but failed with warning "Cannot delete this item from the Report View".

I created a ghost  :'(

Frustrated,
Echo

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Update is not a function
« Reply #10 on: March 08, 2019, 10:42:07 pm »
Running the project integrity check should resolve these type of issues.

Geert