Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Tehila1 on March 09, 2014, 07:34:49 pm

Title: Check if EA template is exist
Post by: Tehila1 on March 09, 2014, 07:34:49 pm
Hello!

How can I check programmatically if an EA template is exist already in a model, by template name?

Thanks in advance!
Title: Re: Check if EA template is exist
Post by: Nizam Mohamed on March 10, 2014, 06:05:11 pm
You can try queries.
If 'tis a document generation template, user defined templates are in t_document (select * from t_document) table.

or if 'tis a code gen / transformation template, user defined changes / new templates are in t_template(select * from t_template)
Title: Re: Check if EA template is exist
Post by: Tehila1 on March 10, 2014, 08:38:01 pm
Thanks a lot!

For other's sake- here is the complete way to check if a document template is exist in current model:  

Code: [Select]
string squery = @"SELECT t_document.DocID FROM t_document WHERE t_document.DocName LIKE 'YourTemplateName' ";
                  XmlDocument result = Repository.SelectStatement(squery);
                  XmlNodeList template = result.SelectNodes("//DocID");
                  if (template.Count <= 0) // The template is missing
Title: Re: Check if EA template is exist
Post by: David Rains (bioform) on March 12, 2014, 08:28:00 am
Where do I find help about parsing the XML results of SQL query (XML is really new to me...) so that bit of code when I checked the EA Help file came up empty?
Title: Re: Check if EA template is exist
Post by: qwerty on March 12, 2014, 09:32:53 am
Which language do you use?

q.
Title: Re: Check if EA template is exist
Post by: David Rains (bioform) on March 12, 2014, 10:34:52 am
Right now vbscript but I am flexible :)
Title: Re: Check if EA template is exist
Post by: David Rains (bioform) on March 12, 2014, 10:36:22 am
BTW I had Inside EA, now today I picked up your other three!  :)
Have to print them out and start reading!

[email protected]
Title: Re: Check if EA template is exist
Post by: Nizam Mohamed on March 12, 2014, 03:40:48 pm
Try this VB Sample code in
Code: [Select]
Dim XmlData As String
      Dim Notes, Script, ScriptLanguage, ScriptName As String
      Dim root, noteX As XElement
      XmlData = Repository.SQLQuery("SELECT Notes FROM t_script)
      root = XElement.Parse(XmlData)
      If root.Elements("Dataset_0").Any() Then
         Notes = root.<Dataset_0>.<Data>.<Row>.<Notes>.Value().ToString()
         noteX = XElement.Parse(Notes)
         ScriptName = noteX.FirstAttribute.Value
         ScriptLanguage = noteX.LastAttribute.Value
      End If
Title: Re: Check if EA template is exist
Post by: qwerty on March 12, 2014, 11:22:47 pm
Quote
BTW I had Inside EA, now today I picked up your other three!  :)
Have to print them out and start reading!

[email protected]
Thanks :-) Hope you enjoy them. If you have any questions or remarks please contact me via mail.

q.