Book a Demo

Author Topic: Creating a tag value for requirement using script  (Read 5433 times)

MV

  • EA User
  • **
  • Posts: 65
  • Karma: +1/-0
    • View Profile
Creating a tag value for requirement using script
« on: June 07, 2011, 03:23:43 pm »
Hi guys,

how can i create a tag value for a requirement type elements using script. I am importing my requirements form Excel data and i have to create a custom colum for my requirement element.

I have used Element.CustomProperties.AddNew(str1,str2) and also
Element.Attributes.AddNew(str1,str2) but none of them is working. However my requirement element is created successfully but without tag value.

CheerS

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Creating a tag value for requirement using scr
« Reply #1 on: June 07, 2011, 04:33:52 pm »
Element.TaggedValues.AddNew(Name, Value)

MV

  • EA User
  • **
  • Posts: 65
  • Karma: +1/-0
    • View Profile
Re: Creating a tag value for requirement using scr
« Reply #2 on: June 08, 2011, 02:23:38 pm »
Thank you very much for your kind help. I have used tag value add function as suggested but i am getting following error

"Cannot use parentheses when calling a sub"

My suntax is like this --
testElement.TaggedValues.AddNew("name","link")

Should I collect returen value from this function. I am not that good in VB programming so please help..

Cheers

MV

  • EA User
  • **
  • Posts: 65
  • Karma: +1/-0
    • View Profile
Re: Creating a tag value for requirement using scr
« Reply #3 on: June 08, 2011, 02:33:34 pm »
Sorry again ,
I have used call statement to add tag values still my requirement element is created with no tag values when i see property of this element.

I am creating this element using folllowing statement
testElement = elements.AddNew( "Login", "Requirement" )
then i used following statement to create tag values
call testElement.TaggedValues.AddNew("name","vinay")

after this i am using update function and refresh funciton.

my requirement element is being created with Login name but there is no tag value.

Thanks

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Creating a tag value for requirement using scr
« Reply #4 on: June 08, 2011, 02:57:26 pm »
See Local Scripts > VBScript - Element Extras Example in the Scripting window for an example of how to create a new tagged value, loop through existing tagged values and delete a tagged value.

AddNew returns a reference to the object being created.  You will typically need to assign this object to a variable and call Update() to commit it to your model.  It's important that you call Update() on any new object before working with any of their contained collections.

Refresh() will reload the entire collection based on the current state of your model.  This is typically only important when items may have been deleted from your model and you need to iterate through this collection again.  You do not typically need to call Refresh after adding a new item.

E.g.

Code: [Select]
dim p As EA.Package
dim e As EA.Element
dim tag As EA.TaggedValue

set p = Repository.GetTreeSelectedPackage()
set e = p.Elements.AddNew("Requirement1", "Requirement")
e.Update
set tag = e.TaggedValues.AddNew("Comment", "Hello World!")
tag.Update

MV

  • EA User
  • **
  • Posts: 65
  • Karma: +1/-0
    • View Profile
Re: Creating a tag value for requirement using scr
« Reply #5 on: June 08, 2011, 03:49:29 pm »
thanks guys, i have found the way...
dim tags as EA.Collection
Dim newTag as EA.TaggedValue
      
set testElement = elements.AddNew( "Login", "Requirement" )

set tags = testElement.TaggedValues
set newTag = tags.AddNew( "MyTag", "Number" )
newTag.Update()