Author Topic: How to link a note to an element feature  (Read 9810 times)

SomersetGraham

  • EA User
  • **
  • Posts: 376
  • Karma: +1/-0
    • View Profile
How to link a note to an element feature
« on: March 11, 2010, 07:59:23 pm »
Hi all
This thread is a feedback on thread
http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1268231528

I have managed to find a way to achieve this but would appreciate any comments in case I have done something wrong!

Linking to element notes
Code: [Select]
string query = "UPDATE t_object SET PDATA1='Element Note' WHERE Object_ID=" + noteElement.ElementID;
Repository.Execute(query);
query = "UPDATE t_object SET PDATA2=" + TargetElement.ElementID + " WHERE Object_ID=" + noteElement.ElementID;
Repository.Execute(query);
query = "UPDATE t_object SET PDATA4='Yes' WHERE Object_ID=" + noteElement.ElementID;
Repository.Execute(query);
This pattern can be followed for other link options but for some of these you need to use PDATA3 as well

Thanks

Graham
Using V12

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to link a note to an element feature
« Reply #1 on: March 11, 2010, 08:06:07 pm »
Graham,

Good that you got it working, and thanks for sharing the solution.
But ultimately this solution is a very ugly workaround. This functionality should be provided as a standard API call.
You can request a feature using the link on the bottom of the page.
This will get the feature request on the internal Sparx list, but unfortunately it will not guarantee implementation.

Geert

SomersetGraham

  • EA User
  • **
  • Posts: 376
  • Karma: +1/-0
    • View Profile
Re: How to link a note to an element feature
« Reply #2 on: March 11, 2010, 08:10:47 pm »
Hi Geert
Feature request made!
Using V12

Hurra

  • EA User
  • **
  • Posts: 183
  • Karma: +0/-0
    • View Profile
    • Find me at LinkedIn!
Re: How to link a note to an element feature
« Reply #3 on: May 16, 2017, 06:21:14 pm »
No news regarding the feature request? I would also like a "clean" solution to link a note to an element feature without the SQL query workaround!

But if I have to do it this way, is it easiest to do a diagram script, select target/source element and execute? Perhaps it's enough to execute the script on the link/relation?

Cheers.
always learning!

Hurra

  • EA User
  • **
  • Posts: 183
  • Karma: +0/-0
    • View Profile
    • Find me at LinkedIn!
Re: How to link a note to an element feature
« Reply #4 on: May 16, 2017, 09:54:39 pm »
I used c as EA.Connector to investigate which link that was of type NoteLink and tried:
Code: [Select]
                                                  Session.Output(c.SupplierID + " -------------- " + c.ClientID);
                                                  query = "UPDATE t_object SET PDATA1='Element Note' WHERE Object_ID="+ c.SupplierID;
                                                  Repository.Execute(query);
                                                  query = "UPDATE t_object SET PDATA2=" + c.ClientID + " WHERE Object_ID=" + c.SupplierID;
                                                  Repository.Execute(query);
                                                  query = "UPDATE t_object SET PDATA4='Yes' WHERE Object_ID=" + c.SupplierID;
                                                  Repository.Execute(query);

and got the error

Error: Microsoft OLE DB Provider for SQL Server [-2147217913]

Operand type clash: int is incompatible with ntext, Line:45

Any tips?

always learning!

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: How to link a note to an element feature
« Reply #5 on: May 17, 2017, 12:03:44 am »
Hello,

the Open Source Addin hoTools (https://github.com/Helmut-Ortmann/EnterpriseArchitect_hoTools) allows you to do this by one click:
- Select Element, Operation, or Attribute on the Diagram
- Click on Feature
hoTools adds a Note which is connected to the selected item.

Kind regards,

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Hurra

  • EA User
  • **
  • Posts: 183
  • Karma: +0/-0
    • View Profile
    • Find me at LinkedIn!
Re: How to link a note to an element feature
« Reply #6 on: May 17, 2017, 05:58:20 pm »
Actually the there were nothing wrong with the queries. There was just a pair of ' ' missing in the second query:

Code: [Select]
query = "UPDATE t_object SET PDATA1='Element Note' WHERE Object_ID=" + c.ClientID;       
Repository.Execute(query);
query = "UPDATE t_object SET PDATA2='" + c.SupplierID + "' WHERE Object_ID=" + c.ClientID;
Repository.Execute(query);
query = "UPDATE t_object SET PDATA4='Yes' WHERE Object_ID=" + c.SupplierID;
Repository.Execute(query);

However, I would also like to refresh the diagram to show the changes in the database, or refresh the Note.

I have these "objects" available:

e as EA.Element (selected from project browser)
c as EA.Connector (from e.Connectors.GetAt())
d as EA.Diagram (from e.Diagrams.GetAt())

My idea was as following:

Code: [Select]
if (d.DiagramID == c.DiagramID)
{
d.DiagramObjects.Refresh;
}

but the script never enters this if statement. Why?

Let me know if you need more code!
always learning!

Hurra

  • EA User
  • **
  • Posts: 183
  • Karma: +0/-0
    • View Profile
    • Find me at LinkedIn!
Re: How to link a note to an element feature
« Reply #7 on: May 17, 2017, 06:21:35 pm »
I just looked up e.Diagrams which do not yield the result I expected...
Code: [Select]
Diagrams
Collection
Read only
Returns a collection of sub-diagrams (child diagrams) attached to this element as seen in the tree view.

I thought it returned a collection of diagrams where the element has occurences.

How can I refresh/update my diagram?
always learning!

Hurra

  • EA User
  • **
  • Posts: 183
  • Karma: +0/-0
    • View Profile
    • Find me at LinkedIn!
Re: How to link a note to an element feature
« Reply #8 on: May 17, 2017, 06:59:19 pm »
Sorry for spamming the thread. Ez solution for my last question:
Code: [Select]
var d as EA.Diagram;
d = Repository.GetCurrentDiagram();
Repository.ReloadDiagram(d.DiagramID);
always learning!