DXL: Attribute Comparison between Two Modules in DOORS

63 views Asked by At

I need to iterate through each object in the "mVerification" module, extract the value of the "(dxl) Req. Id" attribute, and then search for a corresponding object in the "mdata" module with the same value for the "Req. Id" attribute. Then, I need to check if the "Acceptance" attribute of this object in "mdata" has the value "Accepted". If it does, I want to assign the value "True" to a variable s, otherwise "False".

Module mVerification = current Module // Module "mVerification"
Module mdata = read("/Requirements/Analysis/data") // Path to the "mdata" module

Object Verif
Object oDATA
string reqID
string s = null

Object findObjectByReqID(Module mdata, string reqID) {
    Object obj
    for obj in mdata do {
        if (obj."Req. Id" "" == reqID) {
            return obj
        }
    }
    return null
}

for Verif in mVerification do {
    reqID = Verif."(dxl) Req. Id" ""
    oDATA = findObjectByReqID(mdata, reqID)
    
    if (!null oDATA && oDATA."Acceptance" "" == "Accepted") {
        s = "True"
    } else {
        s = "False"
    }
  
    // Display the value of s for this object

}
Display s

My code doesn’t work. It keeps displaying “False” even the condition is “True”.

I would appreciate any assistance in optimizing or improving this approach. Thank you in advance for your contribution!

2

There are 2 answers

4
Mike On

This is code for a DXL Layout column, right? Code for DXL Layout will be called for each object to be displayed. The object to be displayed is given to you in the variable "obj".

So, you do not need the loop for Verif in mVerification, you just need to run the code for the current object, so the code would begin with the statement reqID = obj."(dxl) Req. Id" ""

0
Richard Hesketh On

Try this:

//<compareAcceptance.dxl>

// Compare acceptance state across modules

const string S_REQ_ID_ATTRNAME     = "(dxl) Req. Id"
const string S_ACCEPTANCE_ATTRNAME = "Acceptance"
const string S_ACCEPTED            = "Accepted"
const string S_MDATA_PATH          = "/Requirements/Analysis/data"

Module mVerification = current // Module "mVerification"
Module mData         = read(S_MDATA_PATH, false)  // Path to the "mData" module (false = don't display the opened module on screen)

Object oData = null

bool bResult = null

string sAcceptanceReqID = ""

// Functions
Object findObjectByReqID(Module mData, string sAcceptanceReqID) {
    Object objData

    string sDataReqID = ""

    for objData in mData do {
        sDataReqID = objData.S_REQ_ID_ATTRNAME

        if (sDataReqID == sAcceptanceReqID) {
            return objData
        }
    }
    return null
}

// Main Program
sAcceptanceReqID = obj.S_REQ_ID_ATTRNAME

oData = findObjectByReqID(mData, sAcceptanceReqID)

string sAcceptanceState = oData.S_ACCEPTANCE_ATTRNAME

if ((!null oData) && (sAcceptanceState == S_ACCEPTED)) {
    bResult = true
} else {
    bResult = false
}

// Display the value of s for this object
display (bResult "")

As Mike has pointed out, the 'obj' variable for the current object in a Layout or Attribute DXL context, is your friend here and removes the need for the outer loop in the main function, which does not work in Attribute/Layout contexts (because the DXL interpreter runs the code for each object anyway).

I have also lightly optimised for readability and ease of modification (all the string constants up top) as well as changing variable names to make it a little easier to follow (IMO).

The solution works but will not scale well, as for each refresh of the screen in mVerification, you will (for each object on screen) iterate through every object in mData comparing the string value of the Acceptance attribute. If that becomes a problem, please come back and ask about other ways to achieve this.