Author Topic: Document Generation Bookmarks in SQL Fragments  (Read 2397 times)

potterm

  • EA User
  • **
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Document Generation Bookmarks in SQL Fragments
« on: November 08, 2023, 09:11:28 pm »
Hi,

I have an SQL Template fragment that is reporting on requirements in a table as part of a parent template, and I'd like insert standard EA bookmarks into the generated table (i.e. in "BM_<GUID>" format), so that other element notes that include hyperlinks to those requirements resolve properly.  However I haven't found a way of doing it.

Is this possible from within the EA template?   As a workaround I can generate text tags into my report output and use a Word macro afterwards to convert them into actual bookmarks, but it would be good if I could do this all within the EA SQL template fragment.

Thanks,
Martin

Farkas

  • EA Novice
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Re: Document Generation Bookmarks in SQL Fragments
« Reply #1 on: November 09, 2023, 01:18:43 am »
Hi,

I managed to create bookmarks with custom script fragments. I share the methodology, maybe this is reproducable in sql fragments as well:
The idea is that if you insert RTF into a custom field, EA will generate that into the output document. So if you insert a small chunk of RTF containing only the bookmark itself, it will work.

The heart is this javascript function:
Code: [Select]
// Returns string with bookmark in EA RTF style
// text: text to be marked with bookmark
// eaguid: the GUID of the element/diagram/package/attribute/operation/... from EA repository in EA style (e.g. {384F9831-D3EF-47d1-A565-DE355E0EFC4C})
// Example output (where <<text>> is the input text parameter):
// {\rtf1\ansi\deff0  {\fonttbl {\f0 Times New Roman;}}{\*\bkmkstart BKM_14F08F8E_31B7_491F_93D7_C6EFA8257B90}<<text>>{\*\bkmkend BKM_14F08F8E_31B7_491F_93D7_C6EFA8257B90}}   
function createRTFBookmark(text, eaguid)
{
const rtfstart = '{\\rtf1\\ansi\\deff0  {\\fonttbl {\\f0 Times New Roman;}}';
const rtfend = '}';
const rtfbkmstart = '{\\*\\bkmkstart ';
const rtfbkmend = '{\\*\\bkmkend ';
let rtfguid = guidToBkmStr(eaguid);
return rtfstart + rtfbkmstart + rtfguid + '}' + text + rtfbkmend + rtfguid + '}' + rtfend;
}

Which calls this other js function in order to convert the guid to bookmark format:
Code: [Select]
// Converts EA GUIDs (e.g. '{384F9831-D3EF-47d1-A565-DE355E0EFC4C}')
// to a bookmark string (e.g. 'BKM_14F08F8E_31B7_491F_93D7_C6EFA8257B901')
function guidToBkmStr(eaguid) {
let rtfguid = eaguid.replace('{', '').replace('}', '').replace(/-/g, '_').toUpperCase();
return 'BKM_' + rtfguid;
}

Then I return the result of createRTFBookmark() in the custom xml document (documented here: https://sparxsystems.com/enterprise_architect_user_guide/16.1/model_publishing/example_output_of_an_rtf_templ.html; and here: https://sparxsystems.com/enterprise_architect_user_guide/16.1/model_publishing/example_rtf_template_fragment_.html)
(As per my tests EA doesn't need the formatted="1" attribute for these (RTF) kind of custom fields in the xml.)

My tests shows it is wise to leave the text attribute blank in my function and just use bookmark to point to a position in the document, not to a whole section, because the formating can be ugly.

So, maybe, if you managed to query a custom field containing something like the following RTF (converting ea_guid the correct way), and alias this field in the SQL select to e.g. 'ElementBookmark' and insert the {ElementBookmark} custom field into your fragment, then it can work:
Code: [Select]
{\rtf1\ansi\deff0  {\fonttbl {\f0 Times New Roman;}}{\*\bkmkstart BKM_14F08F8E_31B7_491F_93D7_C6EFA8257B90}{\*\bkmkend BKM_14F08F8E_31B7_491F_93D7_C6EFA8257B90}}
Maybe someone will suggest an easier solution as well.

Farkas
« Last Edit: November 09, 2023, 02:13:44 am by Farkas »

potterm

  • EA User
  • **
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Re: Document Generation Bookmarks in SQL Fragments
« Reply #2 on: November 09, 2023, 02:50:44 am »
Hi Farkas,

Thanks so much for your solution  :) I'll give it a try and let you know how I get on.  Generating the RTF string from a custom SQL fragment will be easy enough I think - the key will be if EA can then interpret it as RTF and convert into a bookmark in the generated document.

Martin

Farkas

  • EA Novice
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Re: Document Generation Bookmarks in SQL Fragments
« Reply #3 on: November 10, 2023, 01:11:20 am »
You're welcome!
Can you confirm if you can achieve this via sql query - after you tried it? I'm just curious, thanks!