Book a Demo

Author Topic: AddRow in SearchWindow  (Read 13892 times)

Colin Coates

  • EA User
  • **
  • Posts: 46
  • Karma: +0/-0
    • View Profile
AddRow in SearchWindow
« on: October 08, 2019, 11:34:18 pm »
I create a custom SQL search named "Unknown GUID" as follows:
Code: [Select]
select ea_guid as CLASSGUID, object_type as CLASSTYPE from t_object where ea_guid = '';
The query above is deliberately constructed to return zero rows in its result set.

I then have the following PHP code:
Code: [Select]
<?php$ea = com_get_active_object('EA.App');$sw = $ea->Repository->SearchWindow;$ea->Repository->RunModelSearch('Unmatched GUID','','','');const otElement = 4;$sw->AddRow(otElement,'09D94D1D-CB0C-4d61-844E-A41C25E706EF',3,'Signal',0); // this element exists$sw->EnsureVisible();$ea = NULL;?>


On running the script (at the command line), I see:
Code: [Select]
<?phpd:\colin.coates\php>php -f search.phpphp -f search.phpPHP Fatal error:  Uncaught com_exception: Error [0x80010105] The server threw an exception. in D:\colin.coates\php\search.php:6Stack trace:#0 D:\colin.coates\php\search.php(6): variant->AddRow(4, '09D94D1D-CB0C-4...', 3, 'Signal', 0)#1 {main}  thrown in D:\colin.coates\php\search.php on line 6

I do not know why this is throwing an exception?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: AddRow in SearchWindow
« Reply #1 on: October 08, 2019, 11:51:36 pm »
I don't think you are passing valid parameters:
From the help
Quote
ot: ObjectType - the Object Type
ElementGUID: String - GUID of the element
ElementID: long - Object ID of the element
ClassType: String - the type of object
Values: an array of values
"otElement" is defined somewhere I guess?
The last parameter "0" doesn't look like an array to me.

Geert

Colin Coates

  • EA User
  • **
  • Posts: 46
  • Karma: +0/-0
    • View Profile
Re: AddRow in SearchWindow
« Reply #2 on: October 09, 2019, 12:42:52 am »
Thanks for replying Geert! :-)

There is a line in the script that defines a constant, so I think that is okay?
Code: [Select]
const otElement = 4;
I tried updating the line that adds a row, including passing an array, as follows:
Code: [Select]
$sw->AddRow(otElement,'{09D94D1D-CB0C-4d61-844E-A41C25E706EF}',3,'Signal',[]); // this element exists
Unfortunately, it still does not fix the exception:
Code: [Select]
PHP Fatal error:  Uncaught com_exception: Error [0x80010105] The server threw an exception.
 in D:\colin.coates\php\search.php:6
Stack trace:
#0 D:\colin.coates\php\search.php(6): variant->AddRow(4, '{09D94D1D-CB0C-...', 3, 'Signal', Array)
#1 {main}
  thrown in D:\colin.coates\php\search.php on line 6

Colin Coates

  • EA User
  • **
  • Posts: 46
  • Karma: +0/-0
    • View Profile
Re: AddRow in SearchWindow
« Reply #3 on: October 09, 2019, 12:48:47 am »
I also tried explicitly creating a Variant object as follows (PHP should already be implicitly creating a Variant anyway) but the exception is still thrown:
Code: [Select]
$sw->AddRow(otElement,'{09D94D1D-CB0C-4d61-844E-A41C25E706EF}',3,'Signal',new VARIANT([])); // this element exists
« Last Edit: October 09, 2019, 12:53:17 am by Colin Coates »

Colin Coates

  • EA User
  • **
  • Posts: 46
  • Karma: +0/-0
    • View Profile
Re: AddRow in SearchWindow
« Reply #4 on: October 09, 2019, 12:51:18 am »
Um, the exception message does look a little different (since it explicitly mentions a Variant object):
Code: [Select]
PHP Fatal error:  Uncaught com_exception: Error [0x80010105] The server threw an exception.
 in D:\colin.coates\php\search.php:6
Stack trace:
#0 D:\colin.coates\php\search.php(6): variant->AddRow(4, '{09D94D1D-CB0C-...', 3, 'Signal', Object(variant))
#1 {main}
  thrown in D:\colin.coates\php\search.php on line 6

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: AddRow in SearchWindow
« Reply #5 on: October 09, 2019, 01:11:27 am »
Have you tried it with an actual filled in array?
You might need to match the number of columns expected by that search.

I'm not sure, though, I don't think I ever used that function before.

When I want to show something in the search window I use
Code: [Select]
Repository.RunModelSearch "","","", dataStringWhere dataString is an XML string that I construct myself. See https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Wrappers/Scripting/SearchResults.vbs for more details

Geert

Colin Coates

  • EA User
  • **
  • Posts: 46
  • Karma: +0/-0
    • View Profile
Re: AddRow in SearchWindow
« Reply #6 on: October 09, 2019, 03:38:34 am »
Thanks again for your assistance Geert! B-)

I've managed to come up with a "hard coded" XML example that is working for me and provides a basis for constructing a dynamically generated result set:
Code: [Select]
<?phpfunction search() : string {    $w = new XMLWriter();    if ($w->openMemory()) {	$w->writeRaw('<ReportViewData>'); // $w->writeRaw('<ReportViewData UID="">');	$w->startElement('Fields');	$w->writeRaw('<Field name="CLASSGUID"/>');	$w->writeRaw('<Field name="CLASSTYPE"/>');	$w->writeRaw('<Field name="Name"/>');	$w->endElement();	$w->startElement('Rows');	$w->startElement('Row');	$w->writeRaw('<Field name="CLASSGUID" value="{09D94D1D-CB0C-4d61-844E-A41C25E706EF}"/>');	$w->writeRaw('<Field name="CLASSTYPE" value="Signal"/>');	$w->writeRaw('<Field name="Name" value="Signal1"/>');	$w->endElement(); // Row	$w->endElement(); // Rows	$w->writeRaw('</ReportViewData>');	return $w->outputMemory();    } else {	return "No\n";    }}$ea = com_get_active_object('EA.App');$sw = $ea->Repository->SearchWindow;$sw->AddColumn('Name', 250);$results=search();echo $results . "\n";$ea->Repository->RunModelSearch('Unmatched GUID','','',$results);$sw->EnsureVisible();$ea = NULL;?>


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: AddRow in SearchWindow
« Reply #7 on: October 09, 2019, 09:42:28 am »
I have an example (written in Javascript) that works.

Code: [Select]
var Search = Repository.SearchWindow;
Search.EnsureVisible();

Search.NewLayout("{not-a-guid}");
Search.AddColumn("Icon", 0);
Search.AddColumn("Name", 80);
Search.AddColumn("Author", 80);

var pkg = Repository.GetTreeSelectedPackage();

var j = 0;
for(var i = 0; i < pkg.Diagrams.Count; i ++)
{
var dgm = pkg.Diagrams.GetAt(i);
var values = [];
values.push("");
values.push(dgm.Name);
values.push(dgm.Author);
Search.AddRow(8,dgm.DiagramGUID, dgm.DiagramID, dgm.Type, values);
Search.SetCellString(j, 1, values[1]);
Search.SetCellString(j, 2, values[2]);
j++;
}


for(var i = 0; i < pkg.Elements.Count; i ++)
{
var e = pkg.Elements.GetAt(i);
var values = [];
values.push("");
values.push(e.Name);
values.push(e.Author);
Search.AddRow(4,e.ElementGUID, e.ElementID, e.Type, values);
Search.SetCellString(j, 1, values[1]);
Search.SetCellString(j, 2, values[2]);
j++;
}