Author Topic: How to add new Tagged Value Types to all Elements in a Project?  (Read 11559 times)

PWarren

  • EA User
  • **
  • Posts: 34
  • Karma: +1/-0
  • EA User - 13 Years
    • View Profile
We are using the Business Process element from BPMN 2.0 <<BusinessProcess>>. I have created 4 new Tagged Value Types (for project management/reporting purposes) and would like to add those to all of the existing Business Process elements in the project en masse vs. having to manually add it to each one, as we have 100s of these.

(I may also want to do this for sub process and call activities as well.)


Sunshine

  • EA Practitioner
  • ***
  • Posts: 1320
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #1 on: August 03, 2018, 07:20:08 am »
Sounds like you've just added the tag values to one of the BPMN 2.0 <<BusinessProcess>> elements rather than define a stereotype with the extra tag values so synching tagged values as won't work.

AFAIKT there are only two ways to add those extra tagged values on mass other than do it manually;
a) Create an MDG with stereotype that has the extra tagged values that extend BPMN 2.0. Then change all the stereotypes and synch tagged values to add all the tagged values. This approach has the advantage that new elements will be created with the tagged values. However this is a fair amount of work and probably a bit more effort than just simply added the tagged values manually.
b) Use a script such as JScript to navigate all the elements down the hierarchy and add the tagged values if they don't already exist. However you'll need to run this periodically as new BPMN elements won't have the tagged values by default.

Probably option b) is your way forward. You'll need some skills in JScript. I did something similar a while back where I needed to change tagged values on mass, see code below. If you modify the tag names and values in the function ChangeElementTags() then run it should work. Caution:  I'd test it on a copy of your repository first rather than just run it on your live data. Once your happy  its works then copy the code onto the live repository and run it. You'll then need to run it to update any new BPMN Business Processes to add the tag values to them.

NOTE whilst trying this out I did notice getting access to tag values for business process on V14  was a little more difficult than V13.5. I could only see the tagged values in the element properties dialog using special actions in the context menu from a diagram.   

Code: [Select]
!INC Local Scripts.EAConstants-JScript

/*
 * This script should be stored as JScript under a Project Brower Group so 
 * it can be executed from the context menu in the project browser
 *
 * Script Name: Add Tagged Values
 * Author: Sunshine
 * Purpose: Adds tagged values to BPMN stereotype <BusinessProcess>
 * Date: 3/08/2018
 */

/*
 * Project Browser Script main function
 */
function OnProjectBrowserScript()
{
// Get the type of element selected in the Project Browser
var treeSelectedType = Repository.GetTreeSelectedItemType();

switch ( treeSelectedType )
{
case otElement :
{
// Code for when an element is selected
var theElement as EA.Element;
theElement = Repository.GetTreeSelectedObject();
ChangeElements( '', theElement);
break;
}
case otPackage :
{
// Code for when a package is selected
var thePackage as EA.Package;
thePackage = Repository.GetTreeSelectedObject();
NavigatePackage("    ",thePackage);
Session.Prompt( "Script Completed, TagValues Added", promptOK );
break;
}

default:
{
// Error message
Session.Prompt( "This script does not support items of this type. Please select a package", promptOK );
}
}
}

function NavigatePackage( indent, thePackage )
{
    // Cast thePackage to EA.Package so we get intellisense
    var currentPackage as EA.Package;
    currentPackage = thePackage;
   
    // Add the current package's name to the list
    Session.Output( indent + currentPackage.Name + " (PackageID=" +
        currentPackage.PackageID + ")" );
   
    // Convert the elements this package contains
    ChangeElementsInPackage( indent + "    ", currentPackage );
   
    // Recursively process any child packages
    var childPackageEnumerator = new Enumerator( currentPackage.Packages );
    while ( !childPackageEnumerator.atEnd() )
    {
        var childPackage as EA.Package;
        childPackage = childPackageEnumerator.item();
        NavigatePackage( indent + "    ", childPackage );
       
        childPackageEnumerator.moveNext();
    }
}

function ChangeElementsInPackage( indent, thePackage )
{
    // Cast thePackage to EA.Package so we get intellisense
    var currentPackage as EA.Package;
    currentPackage = thePackage;
   
    // Iterate through all elements and add them to the list
    var elementEnumerator = new Enumerator( currentPackage.Elements );
    while ( !elementEnumerator.atEnd() )
    {
        var currentElement as EA.Element;
        currentElement = elementEnumerator.item();
ChangeElements(indent+"    ",currentElement );
        elementEnumerator.moveNext();
    }
}

function ChangeElements( indent, theElement )
{
// if workpackage then do change
if (theElement.Stereotype === "BusinessProcess")
{
ChangeElementTags(indent+"    ",theElement );
   // Iterate through all embedded elements and add them to the list
var elementEnumerator = new Enumerator( theElement.Elements );
while ( !elementEnumerator.atEnd() )
{
var currentElement as EA.Element;
currentElement = elementEnumerator.item();
// if workpackage then do change
ChangeElements(indent+"    ",currentElement );
elementEnumerator.moveNext();
}
}
}

function TagValue(tagName,tagValue,tagNotes)
{
    this.tagName = tagName;
    this.tagValue = tagValue;
this.tagNotes = tagNotes
}


// Change element tagValues
function ChangeElementTags( indent, theElement )
{
    // Cast theElement to EA.Element so we get intellisense
    var currentElement as EA.Element;
    currentElement = theElement;

var tagValues = new Array();

//Tag Values to add for BPMN:BusinessProcess
tagValues[0] = new TagValue("TaggedValueName0", "DefaultValue0",""); // Value
tagValues[1] = new TagValue("TaggedValueName1", "DefaultValue1",""); // Value
tagValues[2] = new TagValue("TaggedValueName2", "<memo>","DefaultNotes2"); //Notes
tagValues[3] = new TagValue("TaggedValueName3", "<memo>","DefaultNotes3"); // Notes

var tagEnumerator = new Enumerator( tagValues );

Session.Output( "Processing Element: " + theElement.Name );

while ( !tagEnumerator.atEnd() )
    {
//Session.Output( "Processing Element: " + theElement.Name + ", TagValue:"+tagEnumerator.item());
//Add Tagged Value to Element preserving any existing tagged values
// Set Tagged Notes
//SetElementTaggedNotes(theElement,tagEnumerator.item().tagName, tagEnumerator.item().tagValue,false);
// Set Tagged Value

if (theElement.TaggedValues.GetByName( tagEnumerator.item().tagName ) == null)
{
//If tagname does not exist then add it.
SetElementTaggedValue(theElement,tagEnumerator.item().tagName, tagEnumerator.item().tagValue,tagEnumerator.item().tagNotes,true);
}
tagEnumerator.moveNext();
    }

theElement.Update();

}

/**
  * Retrieves the TaggedValue value from the provided element whose name matches the specified name.
  * If the element does not exist, or does not contain a TaggedValue with the specified name, null
  * is returned.
  *
  * @param[in] theElement (EA.Element) The element to retrieve the TaggedValue value from
  * @param[in] taggedValueName (String) The name of the TaggedValue whose value will be retrieved
  *
  * @return The value of the requested TaggedValue in variant form
  */
function GetElementTaggedValue( theElement /* : EA.Element */, taggedValueName /* : String */, defaultValue /* : String */ ) /* : variant */
{
var result = defaultValue;

if ( theElement != null && taggedValueName.length > 0 )
{
var taggedValue as EA.TaggedValue;
taggedValue = theElement.TaggedValues.GetByName( taggedValueName );

if ( taggedValue != null )
{
result = taggedValue.Value;
Session.Output( "Element Value: " + theElement.Name + " TagValue:"+taggedValueName + "Value = " + result)

}
else
{
Session.Output( "ERROR Element Value: " + theElement.Name + " TagValue:"+taggedValueName + "Doesn't exist");
}
}

return result;
}


function GetElementTaggedNotes( theElement /* : EA.Element */, taggedValueName /* : String */, defaultValue /* : String */ ) /* : variant */
{
var result = defaultValue;

if ( theElement != null && taggedValueName.length > 0 )
{
var taggedValue as EA.TaggedValue;
taggedValue = theElement.TaggedValues.GetByName( taggedValueName );

if ( taggedValue != null )
result = taggedValue.Notes;
}

return result;
}

/**
 * Sets the specified TaggedValue on the provided element. If the provided element does not already
 * contain a TaggedValue with the specified name, a new TaggedValue is created with the requested
 * name and value. If a TaggedValue already exists with the specified name then action to take is
 * determined by the replaceExisting variable. If replaceExisting is set to true, the existing value
 * is replaced with the specified value, if not, a new TaggedValue is created with the new value.
 *
 * @param[in] theElement (EA.Element) The element to set the TaggedValue value on
 * @param[in] taggedValueName (String) The name of the TaggedValue to set
 * @param[in] taggedValueValue (variant) The value of the TaggedValue to set
 * @param[in] replaceExisting (boolean) If a TaggedValue of the same name already exists, specifies
 * whether to replace it, or create a new TaggedValue.
 */
function SetElementTaggedValue( theElement /* : EA.Element */, taggedValueName /* : String */, taggedValueValue /* : variant */, taggedValueNotes /* : variant */,replaceExisting /* : boolean */ ) /* : void */
{
if ( theElement != null && taggedValueName.length > 0 )
{
var taggedValue as EA.TaggedValue;
taggedValue = null;

// If replace existing was specified then attempt to get a tagged value from the element
// with the provided name
if ( replaceExisting )
taggedValue = theElement.TaggedValues.GetByName( taggedValueName );

if ( taggedValue == null )
{
//Add a new taggedValue
taggedValue = theElement.TaggedValues.AddNew( taggedValueName, taggedValueValue );
taggedValue.Notes = taggedValueNotes;
Session.Output( "     Added Element: " + theElement.Name+ ' TaggedValue:'+ taggedValueName + " ="+ taggedValueValue);
}
else
{
taggedValue.Value = taggedValueValue;
taggedValue.Notes = taggedValueNotes;
Session.Output( "     Updated Element: " + theElement.Name+ ' TaggedValue:'+ taggedValueName + " ="+ taggedValueValue);
}

taggedValue.Update();
}
}

function SetElementTaggedNotes( theElement /* : EA.Element */, taggedValueName /* : String */, taggedValueNotes /* : variant */, replaceExisting /* : boolean */ ) /* : void */
{
if ( theElement != null && taggedValueName.length > 0 )
{
var taggedValue as EA.TaggedValue;
taggedValue = null;

// If replace existing was specified then attempt to get a tagged value from the element
// with the provided name
if ( replaceExisting )
taggedValue = theElement.TaggedValues.GetByName( taggedValueName );

if ( taggedValue == null )
{
taggedValue = theElement.TaggedValues.AddNew( taggedValueName, "<memo>" );
taggedValue.Notes = taggedValueNotes;
}
else
{
taggedValue.Notes = taggedValueNotes;
}

taggedValue.Update();
}
}

function DeleteElementTaggedValue( theElement /* : EA.Element */, taggedValueName /* : String */ ) /* : void */
{
if ( theElement != null && taggedValueName.length > 0 )
{
var taggedValue as EA.TaggedValue;
taggedValue = null;

// var taggedValueArray as EA.Element.TaggedValues;
// taggedValue = theElement.TaggedValues


for ( var i = 0; i < theElement.TaggedValues.Count; i++ )
{

// Session.Output( "DELETING Element: "+ theElement.Name + " TagValue:"+ taggedValueName);
taggedValue = theElement.TaggedValues.GetAt(i);
// If the element is the one we just added, then delete it
if ( taggedValue.Name == taggedValueName )
{
Session.Output( "     Deleted Element: " + theElement.Name + ", TagValue:"+theElement.TaggedValues.GetAt(i).Name);
theElement.TaggedValues.DeleteAt(i,false);
theElement.TaggedValues.Refresh();
break;
}
}
}
}

OnProjectBrowserScript();


« Last Edit: August 03, 2018, 10:45:21 am by Sunshine »
Happy to help
:)

Richard Freggi

  • EA User
  • **
  • Posts: 493
  • Karma: +18/-7
    • View Profile
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #2 on: August 03, 2018, 11:09:01 am »
Typing quickly w/out time to look this up in EA: the UML types (or something like that) menu in EA should let you create tagged value types for the whole project - takes 3 minutes.
I'll look it up tomorrow if  you need more details

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #3 on: August 03, 2018, 03:58:48 pm »
Typing quickly w/out time to look this up in EA: the UML types (or something like that) menu in EA should let you create tagged value types for the whole project - takes 3 minutes.
I'll look it up tomorrow if  you need more details
There's a difference between defining tagged value types, and applying them to all elements of a certain type.

Geert

PWarren

  • EA User
  • **
  • Posts: 34
  • Karma: +1/-0
  • EA User - 13 Years
    • View Profile
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #4 on: August 09, 2018, 06:46:52 am »
Thanks everyone for your input on this, especially the example code!

I may consider the MDG as long-term approach and I was researching that too, as we do want the tagged values added as we either add new elements to current models, or when we create new models. Option b and the script provided may be a current quick solution for now, and yeah I always test this out locally first before moving it to the repository.

Is it possible to edit the existing BPMN 2.0 MDG and add my stereotype there? I started researching that but had to shelve it for now.

Ver.14 vs. Ver13.5 - We are all still on 13.5 and per my recommendation, we will be upgrading only one user and evaluating changes to features and existing diagrams, just like we did for 12 to 13.

As just a side note and possible bug/issue I tried adding my tagged values to a few diagrams that contained only business process icons (representing a group of related processes) by selecting all of them at once and adding the tagged values. At first glance it seemed to work but for one tagged value type Check List, where all tick boxes where checked off resulting in a Complete text value, they changed to 1, 1, 1, 1 when I logged back into the EA project file.

If I delete it from one business process icon, and add it back in it works as intended. So it may not be possible to do a group of elements together like I did, or it's a bug.

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1320
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #5 on: August 09, 2018, 10:36:21 am »
Quote
Is it possible to edit the existing BPMN 2.0 MDG and add my stereotype there? I started researching that but had to shelve it for now.
I guess you could modify the MDG technology as is just xml file so you could hack the BPMN 2.0. MDG located in C:\Program Files (x86)\Sparx Systems\EA\MDGTechnologies\BPMN 2.0 Technology.xml

Open the file with text editor and search for the 'Stereotype' tag then find the next 'tagged values' tag. Copy one the the tag names and add your new one.
<Stereotype name="BusinessProcess" .../>
<TaggedValues>
<Tag name= ... />

You then need to copy the file to some place all users can access and point Sparx EA to that using the advanced options. You need to figure a way not to have conflicts with the original BPMN 2.0 mdg. Easiest way is to just rename it to BPMN 2.0 Technology.bak located in C:\Program Files (x86)\Sparx Systems\EA\MDGTechnologies\ for all users or simply delete it.

Happy to help
:)

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1320
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #6 on: August 09, 2018, 10:39:57 am »
Ver.14 vs. Ver13.5 - We are all still on 13.5 and per my recommendation, we will be upgrading only one user and evaluating changes to features and existing diagrams, just like we did for 12 to 13.
Note accessing tagged values in V14 is a little more difficult.

As just a side note and possible bug/issue I tried adding my tagged values to a few diagrams that contained only business process icons (representing a group of related processes) by selecting all of them at once and adding the tagged values. At first glance it seemed to work but for one tagged value type Check List, where all tick boxes where checked off resulting in a Complete text value, they changed to 1, 1, 1, 1 when I logged back into the EA project file.
Yeah you can only see tagged values for one element so you would added to only one even though you had selected multiple elements. Probably the one first one you selected
Happy to help
:)

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #7 on: August 09, 2018, 10:48:56 am »
Quote
Is it possible to edit the existing BPMN 2.0 MDG and add my stereotype there? I started researching that but had to shelve it for now.
I guess you could modify the MDG technology as is just xml file so you could hack the BPMN 2.0. MDG located in C:\Program Files (x86)\Sparx Systems\EA\MDGTechnologies\BPMN 2.0 Technology.xml

Open the file with text editor and search for the 'Stereotype' tag then find the next 'tagged values' tag. Copy one the the tag names and add your new one.
<Stereotype name="BusinessProcess" .../>
<TaggedValues>
<Tag name= ... />

You then need to copy the file to some place all users can access and point Sparx EA to that using the advanced options. You need to figure a way not to have conflicts with the original BPMN 2.0 mdg. Easiest way is to just rename it to BPMN 2.0 Technology.bak located in C:\Program Files (x86)\Sparx Systems\EA\MDGTechnologies\ for all users or simply delete it.

There's new functionality that means you don't have to do any of the above. Have a look at http://www.sparxsystems.com/enterprise_architect_user_guide/14.0/modeling_tools/redefine_ster_other_prof.html. This should allow you to create your own profile that redefines one or more BPMN stereotypes to have additional tagged values.
The Sparx Team
[email protected]

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8083
  • Karma: +118/-20
    • View Profile
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #8 on: August 09, 2018, 01:53:57 pm »
Note accessing tagged values in V14 is a little more difficult.
How so? I saw another complaint about this earlier today. As with yours, it didn't describe why it is more difficult.

I don't think the tagged values window changed in version 14. The general properties changed so that there are less different places where you need to access properties. The profile tagged values are included with that, so it should be easier than previous versions to access them.

PWarren

  • EA User
  • **
  • Posts: 34
  • Karma: +1/-0
  • EA User - 13 Years
    • View Profile
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #9 on: August 14, 2018, 03:15:47 am »
Thanks Sunshine & KP for the responses!

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1320
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #10 on: August 14, 2018, 07:01:37 am »
Note accessing tagged values in V14 is a little more difficult.
How so? I saw another complaint about this earlier today. As with yours, it didn't describe why it is more difficult.

I don't think the tagged values window changed in version 14. The general properties changed so that there are less different places where you need to access properties. The profile tagged values are included with that, so it should be easier than previous versions to access them.
Took me ages to find how to get the tagged values window back up after installing V14 because enabling it had moved and it wasn't obvious where it had gone.
Found it now so all good.
Happy to help
:)

Eamonn John Casey

  • EA User
  • **
  • Posts: 110
  • Karma: +0/-1
    • View Profile
Re: How to add new Tagged Value Types to all Elements in a Project?
« Reply #11 on: August 14, 2018, 07:53:10 pm »
It is relatively easy to add a UML Type -> Tagged Values With a drop Down list or whatever you need.
Then use the import/export feature and edit the values in Excel.
Tip: Excel can configure the tagged value column to reference a predefined list to make it easy to choose the correct value.