Book a Demo

Author Topic: Find GUID of Element by Name - CSV Import  (Read 12698 times)

Adam105

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Find GUID of Element by Name - CSV Import
« on: March 20, 2015, 11:21:07 pm »
Hello all,

I am attempting to import a CSV file containing information about connectors and to then create these connectors. I have used the inbuilt JScript - CSV file as a template, and have been attempting to create my own 'OnRowImported' function. I have used the example on the following link as my basis;

http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1396913036/0#1

Code: [Select]
function OnRowImported()
{
      rowCount++;

      // get all values for this row
      var ColumnSource = CSVIGetColumnValueByName("Source");
      var ColumnSourceType = CSVIGetColumnValueByName("Source Type");
      var ColumnRelationship = CSVIGetColumnValueByName("Relationship");
      var ColumnDirection = CSVIGetColumnValueByName("Direction");
      var ColumnRelName = CSVIGetColumnValueByName("Rel. Name");
      var ColumnRelAlias = CSVIGetColumnValueByName("Rel. Alias");
      var ColumnRelDescription = CSVIGetColumnValueByName("Rel. Description");
      var ColumnDestination = CSVIGetColumnValueByName("Destination");
      var ColumnDestinationType = CSVIGetColumnValueByName("Destination Type");
      var ColumnVisibility = CSVIGetColumnValueByName("Visibility");
      
      Session.Output("Importing: " + ColumnSource);
      Session.Output("Importing: " + ColumnSourceType);
      Session.Output("Importing: " + ColumnRelationship);
      Session.Output("Importing: " + ColumnDirection);
      Session.Output("Importing: " + ColumnRelName);
      Session.Output("Importing: " + ColumnRelAlias);
      Session.Output("Importing: " + ColumnRelDescription);
      Session.Output("Importing: " + ColumnDestination);
      Session.Output("Importing: " + ColumnDestinationType);
      Session.Output("Importing: " + ColumnVisibility);
      
      // Identify Source and Target Element
      SourceElement = Repository.GetElementByGUID(ColumnSource)
      TargetElement = Repository.GetElementByGUID(ColumnDestination)

      // Display in System output the names of the Source and Target Element
      Session.Output(SourceElement.Name)
      Session.Output(TargetElement.Name)

      // Creates new connector between Source and Target Elements
      NewConnector = SourceElement.Connectors.AddNew(ColumnRelName, ColumnRelationship)
      NewConnector.SupplierID = TargetElement.ElementID;
      NewConnector.Direction = ColumnDirection;
      NewConnector.Update();
}

I have got it working if I run the above script, but place an actual GUID in the form of a string, in the brackets;

Code: [Select]
     SourceElement = Repository.GetElementByGUID("D6B15117-F97E-4fd7-A9C0-BL26CA65F761")
      TargetElement = Repository.GetElementByGUID("A495C894-KR59-4ed1-25RF-B170E7F5497F")

I realise I am using 'GetElementbyGUID' but I am uncertain of an alternative. My main question is, is there a way for me to look up the GUID of my element within the script? I'm fairly certain there must be a way, but I'm just very new to this.

Thanks a lot

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Find GUID of Element by Name - CSV Import
« Reply #1 on: March 20, 2015, 11:36:04 pm »
Quote
is there a way for me to look up the GUID of my element within the script?
What do you mean by that?

Geert

Adam105

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Find GUID of Element by Name - CSV Import
« Reply #2 on: March 20, 2015, 11:42:30 pm »
So I am importing the object title of an element, and I wish to find the associated GUID (All of the objects are already imported using the EA Built in CSV import). I just need to make the jump between object title and the GUID (Or find the element not using the GUID) Any ideas?

Thanks for the quick response

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Find GUID of Element by Name - CSV Import
« Reply #3 on: March 21, 2015, 12:27:32 am »
I guess somewhere in the script you create the element. At that place just safe the object in a hash for later reference with the connector creation.

q.

Adam105

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Find GUID of Element by Name - CSV Import
« Reply #4 on: March 21, 2015, 12:47:45 am »
I decided to use a VLOOKUP in Excel, and to just add two additional columns in my CSV file for the Source elements GUID and target element GUID. Still not working however. The system output is saying that an Object is required.

Code: [Select]
function OnRowImported()
{
      rowCount++;

      // get all values for this row
      var ColumnSource = CSVIGetColumnValueByName("Source");
      var SourceGUID = CSVIGetColumnValueByName("SourceGUID");
      var ColumnSourceType = CSVIGetColumnValueByName("Source Type");
      var ColumnRelationship = CSVIGetColumnValueByName("Relationship");
      var ColumnDirection = CSVIGetColumnValueByName("Direction");
      var ColumnRelName = CSVIGetColumnValueByName("Rel. Name");
      var ColumnRelAlias = CSVIGetColumnValueByName("Rel. Alias");
      var ColumnRelDescription = CSVIGetColumnValueByName("Rel. Description");
      var ColumnDestination = CSVIGetColumnValueByName("Destination");
      var DestinationGUID = CSVIGetColumnValueByName("DestinationGUID");
      var ColumnDestinationType = CSVIGetColumnValueByName("Destination Type");
      var ColumnVisibility = CSVIGetColumnValueByName("Visibility");
      
      Session.Output("Importing: " + ColumnSource);
      Session.Output("Importing: " + SourceGUID);
      Session.Output("Importing: " + ColumnSourceType);
      Session.Output("Importing: " + ColumnRelationship);
      Session.Output("Importing: " + ColumnDirection);
      Session.Output("Importing: " + ColumnRelName);
      Session.Output("Importing: " + ColumnRelAlias);
      Session.Output("Importing: " + ColumnRelDescription);
      Session.Output("Importing: " + ColumnDestination);
      Session.Output("Importing: " + DestinationGUID);
      Session.Output("Importing: " + ColumnDestinationType);
      Session.Output("Importing: " + ColumnVisibility);
      
      // Identify Source and Target Element
      SourceElement = Repository.GetElementByGUID(SourceGUID)
      TargetElement = Repository.GetElementByGUID(DestinationGUID)

      // Display in System output the names of the Source and Target Element
      Session.Output(SourceElement.Name)
      Session.Output(TargetElement.Name)

      // Creates new connector between Source and Target Elements
      NewConnector = SourceElement.Connectors.AddNew(ColumnRelName, ColumnRelationship)
      NewConnector.SupplierID = TargetElement.ElementID;
      NewConnector.Direction = ColumnDirection;
      NewConnector.Update();
}

I'm certain the error is on the lines below, but I just don't have enough experince to know how to resolve this. If I replace SourceGUID and DestinationGUID, with actual GUID's in a string, my code works.

Thanks for your help so far guys

Code: [Select]
     SourceElement = Repository.GetElementByGUID(SourceGUID)
      TargetElement = Repository.GetElementByGUID(DestinationGUID)

« Last Edit: March 21, 2015, 12:59:39 am by Adam105 »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Find GUID of Element by Name - CSV Import
« Reply #5 on: March 21, 2015, 01:19:53 am »
How do your GUIDs look like. You can test-find them with a SQL in the query builder of EA:
Code: [Select]
SELECT * FROM t_object WHERE ea_guid='<your guid>'Just replace <your guid> by the one you want to test.

q.

Adam105

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Find GUID of Element by Name - CSV Import
« Reply #6 on: March 21, 2015, 02:26:00 am »
You were correct Querty, it was an issue with my GUIDS. Thanks for all your help!