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:
!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?