Book a Demo

Author Topic: Accessing CallOperation of an action through scripting  (Read 4329 times)

umarkhan

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Accessing CallOperation of an action through scripting
« on: April 12, 2018, 10:55:55 pm »
Hello everybody,

I have been facing an issue for quite some time and cannot find some documentation about it. I would highly appreciate if somebody can give me a hint.

I have defined "Actions" in an activity diagram. These actions are "Call Operation" types. Then I defined the "Call Operations" from the properties > Call > Behavior. Now I want to access these through scripting. To simply, I am looking for something like "Action.CallOperation" or similar so that I can find out the call behavior for an action. Any help will be highly appreciated. Thanks

Kind regards
Khan

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Accessing CallOperation of an action through scripting
« Reply #1 on: April 13, 2018, 06:09:41 pm »
Hello,


The operation which a CallOperation action calls is stored as the action's classifier, enabling you to locate the operation from the action (in a diagram) by hitting Ctrl-Alt-G.

What complicates matters is that EA actually stores an element's classifier in two ways in the database -- t_object.Classifier holds the classifier's element ID, which is an integer, and t_object.Classifier_guid holds its GUID, which is a string.
Only t_object.Classifier is reflected in the API (Element.ClassifierID), and it's only valid for elements whose classifier is another element (eg Objects). t_object.Classifier_guid, which is used for CallOperation actions, cannot be retrieved through the API.

Instead, you have to go to the database. To retrieve the operation, do something like

Code: (VBScript) [Select]
queryResult = Repository.SQLQuery("select Classifier_guid from t_object where Object_ID=" & element.ElementID)

' You'll need to parse the returned XML text here. A quick and dirty way in this case, since you know
' there should be exactly one result and the tags are always the same, is a hard-coded Mid() call.

methodGuid = Mid(queryResult, 120, 38)

method = Repository.GetMethodByGuid(methodGuid)

HTH,


/Uffe
« Last Edit: April 13, 2018, 06:11:12 pm by Uffe »
My theories are always correct, just apply them to the right reality.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Accessing CallOperation of an action through scripting
« Reply #2 on: April 13, 2018, 06:51:30 pm »
I'd rather parse the XML result than just getting the relevant part via string-subscript. But as long as you know what you're doing and Sparx is not changing the XML format, this is the only way.

q.

umarkhan

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Accessing CallOperation of an action through scripting
« Reply #3 on: April 17, 2018, 09:59:55 pm »
@ Uffe,

thank you for your detailed answer.
I also found out that the Actions with CallOperations are different from Atomic Actions only in the classifier ID if one looks in the sql tables.
I will try the way you mentioned (though in Python). Thank you for the hint

@ qwerty

that would be my last resort if nothing else works. Thanks :)