Book a Demo

Author Topic: DocumentGenerator.DocumentElement: nDepth seems to do not work.  (Read 5068 times)

jepessen

  • EA User
  • **
  • Posts: 106
  • Karma: +1/-1
    • View Profile
DocumentGenerator.DocumentElement: nDepth seems to do not work.
« on: November 18, 2020, 10:19:07 am »
Hi.

I'm creating a custom document for analyzing requirements and test case.
I want to create a section for every phase.
In every section I want to list requirements for every phase.

So the structure of the document is

- Phase XXX (heading 1)
-- Requirements list (heading 2)
--- Requirement YYY (heading 3)

Requirement YYY is created with DocumentElement method of DocumentGenerator class, passing the ID of the requirement.

This is the example script:

Code: [Select]
!INC Local Scripts.EAConstants-JScript

function createStartPage(generator)
{
generator.InsertCoverPageDocument("Portrait");
generator.InsertBreak(0);
generator.InsertText("Table of Contents\n", "Table of Contents");
generator.InsertTableOfContents();
generator.InsertBreak(0);
}

function saveDocument(generator)
{
generator.saveDocument("d:/testcases.docx", 3);
}

function replaceDocumentField(generator)
{
generator.ReplaceField("ReportTitle", "Test Cases for Acceptance");
}

function getPhaseList()
{
var requirementsQuery = "select distinct Phase FROM t_object where Object_Type = 'Requirement' order by Phase asc;";
var elements = Repository.SQLQuery(requirementsQuery);
var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.6.0");
xmlDoc.async = false;
xmlDoc.loadXML(elements);
    var phases = [];
var nodes = xmlDoc.getElementsByTagName("Phase");
for (var i=0; i < nodes.length; i++) {
if (nodes.item(i).text != "") {
phases[i] = nodes.item(i).text;
}
    }
return phases;
}

function getRequirementListWithPhase(phase)
{
var requirementsQuery = "SELECT * FROM t_object where Object_Type = 'Requirement' and Phase = '" + phase + "';";
var elements = Repository.GetElementSet(requirementsQuery, 2);
return elements;
}

function createPhaseSection(generator, phase)
{
generator.InsertText("Phase " + phase + "\n", "heading 1");
generator.InsertText("Requirements\n", "heading 2");
requirements = getRequirementListWithPhase(phase);
for (var i = 0; i < requirements.Count; i++) {
requirement = requirements.GetAt(i);
generator.DocumentElement(requirement.ElementID, 3, "Requirement Report - Details");
}

}

function createPhaseSections(generator)
{
var phases = getPhaseList();
var i = 0;
for (key in phases) {
var p = phases[key];
Session.Output("- Found Phase: " + p);
createPhaseSection(generator, p);
if (i == 0) {
break;
}
i++;
}
}

function main()
{
Session.Output("003 - Insert Requirements list for every phase");
// Some prework for cleaning environment
Repository.EnsureOutputVisible( "Script" );
Repository.ClearOutput("Script");
Session.Output("Starting document generation");
var generator = Repository.CreateDocumentGenerator();
generator.NewDocument("");
generator.SetStyleSheetDocument("Numbered Headings");
createStartPage(generator);
createPhaseSections(generator);
replaceDocumentField(generator);
saveDocument(generator);
}

main();

The document is generated, but headings are not consistent. What I'm expecting, since I've set the "Numbered Headings" stylesheet, is to obtain something like

1 Phase 0.01
1.1 Requirements
1.1.1 Req 001
......
1.1.2 Req 002
....

etc...

As you can see from the screenshot and from the document headings are wrong. Phase section and Requirements subsection have no numbering, and the single requirement subsubsection has Heading 1, while I've put 3 as depht in DocumentElement generator method.

What I'm doing wrong and what should I do in order to fix it?


Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: DocumentGenerator.DocumentElement: nDepth seems to do not work.
« Reply #1 on: November 19, 2020, 07:25:21 pm »
Hi,


The built-in template "Requirement Report - Details" isn't intened to be used this way. It's intended to be run on a package and produce a full document on its own. DocumentGenerator.DocumentElement() is intended to produce output for a single element into the DocumentGenerator's stream. I recommend you create your own template to output the details you want for an element and use that instead.

As a general rule, when using Repository.GetElementSet(..., 2) only select t_object.Object_ID because that's all EA uses -- the element details are retrieved separately behind the scenes. This makes no difference to small queries, but it will have an impact on large ones.

The manual states that DocumentGenerator.SetStyleSheetDocument() "can be called before NewDocument." Try that, I think it might be ignored otherwise. Again, mixing built-in templates with DocumentGenerator is off the beaten track and may well have surprising consequences.

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

jepessen

  • EA User
  • **
  • Posts: 106
  • Karma: +1/-1
    • View Profile
Re: DocumentGenerator.DocumentElement: nDepth seems to do not work.
« Reply #2 on: November 20, 2020, 05:49:48 am »
Thanks. I've tried to create custom fragments and to set the depth of heading and it seems to work.

Now I'm trying to define style for custom text, but It doesn't follow the numbering. I've tried to put the DocumentGenerator.SetStyleSheetDocument() before creating new document but headings are not numbered for custom text, while it's done for headings of fragments. As you can see in the image The section created with DocumentElement are numbered, while the section created manually are not numbered. Is there a way to number them with InsertText?