Book a Demo

Author Topic: set Effect in Actions  (Read 3782 times)

Carsten Neumann

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
set Effect in Actions
« on: June 15, 2011, 06:38:10 pm »
Hi,

I have a problem setting the effect in an Action. I tried the following code but when I open the Model in EA the effect is empty.
I think I'm missing a save/update, but where?
            EA.Element na1 = activity.Elements.AddNew("Action1", "Action");
            na1.Notes = "Action1 Note";
            
            foreach (EA._CustomProperty o in na1.CustomProperties)
            {
                if (o.Name.Equals("effect"))
                {
                    o.Value = "Effect of Action1";
                }
            }
            na1.CustomProperties.Refresh();
            na1.Refresh();
            if (!na1.Update())
            { MessageBox.Show(na1.GetLastError()); }

Cheers
Carsten

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: set Effect in Actions
« Reply #1 on: June 16, 2011, 08:15:20 am »
Quote
I haven't tried running this. But my guess is in red below.

            EA.Element na1 = activity.Elements.AddNew("Action1", "Action");
            na1.Notes = "Action1 Note";
            
            foreach (EA._CustomProperty o in na1.CustomProperties)
            {
                if (o.Name.Equals("effect"))
                {
                    o.Value = "Effect of Action1";
                    o.Update();
                }
            }
            na1.CustomProperties.Refresh();
            na1.Refresh();
            if (!na1.Update())
            { MessageBox.Show(na1.GetLastError()); }

Cheers
Carsten

Carsten Neumann

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: set Effect in Actions
« Reply #2 on: June 17, 2011, 01:18:29 am »
Hi Simon,

I thought the same. Unfortunately CustomProperty does not have an Update() Methode.

Any other ideas?

Carsten

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: set Effect in Actions
« Reply #3 on: June 17, 2011, 09:25:50 am »
Just another suggestion - try removing your Refresh() calls.  Calling Refresh() before you call Update() will effectively undo all your changes before you have committed them to the database.

It's possible that the call to Element.Update will commit your changes to the CustomProperties values.

E.g.
           EA.Element na1 = activity.Elements.AddNew("Action1", "Action");
           na1.Notes = "Action1 Note";
          
           foreach (EA._CustomProperty o in na1.CustomProperties)
           {
               if (o.Name.Equals("effect"))
               {
                   o.Value = "Effect of Action1";
               }
           }
          //na1.CustomProperties.Refresh();
           //na1.Refresh();
          if (!na1.Update())
           { MessageBox.Show(na1.GetLastError()); }