Home / eaDocX Homepage / EaDocX Help / eaDocX Script examples / Advanced tables
Advanced tables
function Blocks() { // Parameters passed to the script: // ElementGuids - guids of some elements. May be only one. // Repository // Tell eaDocX that this is an eaDocX Script //<Type>eaDocX</Type> //Script to do special printing of Block class elements. //Prints a sub-table of related Requirements // Get the list of GUIDs from the parameter passed by eaDocX var elemGuids = ElementGuids.toString(); // Split them up into individual GUIDs for processing var guids = elemGuids.split(","); // Create a string to hold the HTML var outputHTML = "<table border='1' style='border-collapse: collapse;'>\r\n"; outputHTML += "<tr><th>Name</th><th>Stereotype</th><th>Linked Requirements</th></tr>\r\n"; for (var i = 0; i < guids.length; i++) { var guid = guids.trim(); var el = Repository.GetElementByGuid(guid); if (el !== null) { var linkedRequirements = []; // Find linked Requirement elements via Realisation connectors for (var j = 0; j < el.Connectors.Count; j++) { var connector = el.Connectors.GetAt(j); if (connector.Type === "Realisation") { var otherElement = null; if (connector.ClientID === el.ElementID) { otherElement = Repository.GetElementByID(connector.SupplierID); } else if (connector.SupplierID === el.ElementID) { otherElement = Repository.GetElementByID(connector.ClientID); } if (otherElement !== null && otherElement.Type === "Requirement") { linkedRequirements.push(otherElement); } } } // Build the row in the main table outputHTML += "<tr>"; outputHTML += "<td>" + el.Name + "</td>"; outputHTML += "<td>" + (el.Stereotype || "") + "</td>"; // Start sub-table or show empty message outputHTML += "<td>"; if (linkedRequirements.length > 0) { outputHTML += "<table border='1' style='border-collapse: collapse;'>\r\n"; outputHTML += "<tr><th>Requirement Name</th><th>Notes</th></tr>\r\n"; for (var r = 0; r < linkedRequirements.length; r++) { var req = linkedRequirements[r]; outputHTML += "<tr>"; outputHTML += "<td>" + req.Name + "</td>"; outputHTML += "<td>" + (req.Notes || "").replace(/\r?\n/g, "<br>") + "</td>"; outputHTML += "</tr>\r\n"; } outputHTML += "</table>"; } else { outputHTML += "<i>No linked requirements</i>"; } outputHTML += "</td>"; // Close the <td> that wraps the sub-table or message outputHTML += "</tr>\r\n"; } } outputHTML += "</table>\r\n"; return outputHTML; } // Call the function result = Blocks();