Book a Demo

Author Topic: setting Tagged value notes in javascript  (Read 7336 times)

Damir

  • EA User
  • **
  • Posts: 84
  • Karma: +0/-0
    • View Profile
setting Tagged value notes in javascript
« on: June 10, 2010, 11:59:44 pm »
I'm trying to set in an project browser java script a tag's notes field to a value like this:
Code: [Select]
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
                                    aTag.Notes = "kaj ima lima";
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
it creates some error. I can't figure out what error (I'm not at home with scripting in EA). If I remove the line aTag.Notes = "kaj ima lima"; then a tag is added to the element. If this line of code is present, the tag is not added to the element. I need to set value of the tag of type <memo> to a certain value.
What is the right way to do this?
Thanks.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13455
  • Karma: +571/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: setting Tagged value notes in javascript
« Reply #1 on: June 11, 2010, 04:52:40 pm »
Read the doc on the addNew(name,type) operation.
So I would expect something like
addNew("myTaggedValueName","TaggedValue");

then you need to set the value to "<memo>", and then you should be fine.

Geert

Damir

  • EA User
  • **
  • Posts: 84
  • Karma: +0/-0
    • View Profile
Re: setting Tagged value notes in javascript
« Reply #2 on: June 11, 2010, 05:50:45 pm »
Hi Geert,
thank you for answering. Unfortunatelly that's not working. The documentation is extremely slim here. I'll go into more details what I have already tried out:
Here is the complete code of the script (don't mind the code comments):
Code: [Select]
function OnProjectBrowserScript()
{
      // Get the type of element selected in the Project Browser
      var treeSelectedType = Repository.GetTreeSelectedItemType();
      
      switch ( treeSelectedType )
      {
            case ELEMENT_OT:
            {
                  // Code for when an element is selected
                  var theElement as EA.Element;
                  var aTag as EA.TaggedValue;
                                                      
                  theElement = Repository.GetTreeSelectedObject();
                  // dodavanje tagova na razini elementa,  nije izdvojeno u zasebnu funkciju, moglo bi se jer je isti dio koda kao za paket.
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:Neprora[ch269]unskiKorisnici","True");
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:DuNeZupanija","True");
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:HZZO","True");
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:HZZOZZR","True");
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:ZZJZ","True");
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
                  //aTag.Notes                  = "kaj ima lima";
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  //dodavanje taga za opis za sve na razini atributa elementa
                  var attributes as EA.Collection;
                  attributes = theElement.Attributes;
                  var anAttributeTag as EA.AttributeTag;
                  anAttributeTag = null;
                  
                  for ( var i = 0 ; i < attributes.Count ; i++ )
                  {
                        var currentAttribute as EA.Attribute;
                        currentAttribute = attributes.GetAt( i );
                        
                        anAttributeTag = currentAttribute.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
                                                anAttributeTag.Update();
                        currentAttribute.TaggedValues.Refresh();
                        anAttributeTag = null;
                  }
                  
                  
                  break;
            }
            case PACKAGE_OT:
            {
                  // Code for when a package is selected
                  var thePackage as EA.Package;
                  var theElement as EA.Element;
                  var aTag as EA.TaggedValue;
                  thePackage = Repository.GetTreeSelectedObject();
                  theElement = thePackage.Element;
                  
                  // dodavanje tagova na razini paketa,  nije izdvojeno u zasebnu funkciju, moglo bi se jer je isti dio koda kao za element.
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:Neprora[ch269]unskiKorisnici","True");
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:DuNeZupanija","True");
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:HZZO","True");
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:HZZOZZR","True");
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:ZZJZ","True");
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
                  
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
                  
                  
                  break;
            }

            default:
            {
                  // Error message
                  Session.Prompt( "greška, to se ne može napraviti na ovom tipu UML elementa.", 0 );
            }
      }
}
This code WORKS:
- the tags that are being added are defined on the Tagged Value Types tab of the UML Types dialog box.
- All tags that have "Instalacija" string in them are of type "Boolean"
- All tags that have "Opis" string in them are of type "Memo"
- when the script adds a tag like this: aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:ZZJZ","True"); the first argument is used as the tag name, and the second argument is used as the TAG VALUE not as the tag type.
- in the previous example, if I put for the second argument value "Boolean" instead of "True", the value of the tag is "Boolean" instead of default value for that tag; and on the drop-down list for values for that tag in the Tagged Values window you can (and should) only select values True and False.
- on the other hand, if I change aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>"); to aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","WHATEVER I PUT HERE DOESN'T MATTER"); - it nevertheless creates tagged value of type Memo (as it should)...

Damir

  • EA User
  • **
  • Posts: 84
  • Karma: +0/-0
    • View Profile
Re: setting Tagged value notes in javascript
« Reply #3 on: June 11, 2010, 05:51:39 pm »
...continued from the previous post

but the value of the tag of type memo is empty. Value for memo tag should be placed in Notes attribute of the tagged value. So I tried
Code: [Select]
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
                  aTag.Notes = theElement.Notes;
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                 
But, whenever I try to add any constant or other value to aTag.Notes, something breakes without prompting and the tag is not being created.

Please help
thanks

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13455
  • Karma: +571/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: setting Tagged value notes in javascript
« Reply #4 on: June 11, 2010, 06:18:19 pm »
Damir,

Seems like you are using undocumented side effects of the AddNew() operation.
In my code I always do:
Code: [Select]
wrappedElement.TaggedValues.AddNew(name, "TaggedValue")If needed I then set the value and notes of the tagged value.
In your case that would need to be
Code: [Select]
aTag.Value = "<memo>";
aTag.Notes = "whatever long explanation you want to write here";
aTag.Update();

Geert

Damir

  • EA User
  • **
  • Posts: 84
  • Karma: +0/-0
    • View Profile
Re: setting Tagged value notes in javascript
« Reply #5 on: June 11, 2010, 06:40:26 pm »
hm, nope, it still doesn't work.

I tried following based on your example:

Code: [Select]
aTag = null;
                  
                  aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
                  aTag.Value = "<memo>";
                  aTag.Notes                  = "kaj ima lima";
                  aTag.Update();
                  theElement.TaggedValues.Refresh();
                  aTag = null;
the tag was not created. I found out following:
- if I remove line aTag.Notes = "kaj ima lima"; - the tag is still not being created. - which means that even if I try to do aTag.Value = "<memo>"; - it generates some kind of error.
- if i remove both of those lines - the tag is created.
I'm using EA build 855.

any ideas?

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8607
  • Karma: +257/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: setting Tagged value notes in javascript
« Reply #6 on: June 11, 2010, 06:49:52 pm »
Immediately download 857 and see if the problem is still there...

If so, then change the first "<memo>" to not "<memo>" (as Geert has suggested) and see if that changes anything...

I, too, have previously used the same code as you initially disclosed and it used to work...

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Damir

  • EA User
  • **
  • Posts: 84
  • Karma: +0/-0
    • View Profile
Re: setting Tagged value notes in javascript
« Reply #7 on: June 11, 2010, 08:59:11 pm »
Thanks Paolo

that didn't solve the problem. I've isolated the problem - this is a wierd one:
I've created JavaScript initialy (EA generates the skeleton of the code) and that code was presented in these posts - and it worked for everything except assigning values to Notes fields or Value fields.
Then I've created JScript script and copy-pasted everything from JavaScript script to this one - and it all works!

I don't know these languages that much so I can't say should this be normal - in case it isn't - than EA has a bug here...

Regards
Damir

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8607
  • Karma: +257/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: setting Tagged value notes in javascript
« Reply #8 on: June 11, 2010, 10:07:59 pm »
Ah... Yes - I was talking about C# in my Add-In.

Please report a bug to Sparx...

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!