ibm-doors

IBM DOORS DXL script to search for an ID inside a requirement text, and then linking it to another module with the same ID


I am new to DOORS DXL scripting and I am facing some issues with a script I have trying to write. I want to achieve the following: We have two DOORS modules: a source module and a target module. You need to create links between specific objects in these modules based on certain criteria. What needs to be achieve:

In the source module: Look at each object's "System Req" attribute. Search for strings that start with "ONESYS" and end with some random numbers (more than one digit). In the target module: Search the "Original ID" attribute for the strings found in the source module. Linking: When a match is found between the "ONESYS" string in the source module and the "Original ID" in the target module, create a link between these two objects. The links should be created in a specified link module. The process should be automated and efficient, capable of handling large modules with many objects. The goal is to automate the process of identifying related objects between the two modules based on the "ONESYS" identifier and creating the appropriate links, thereby establishing traceability between the source and target modules. I have the following script but I get errors indicating incorrect argument for (->), exists, and if. I use DOORS 9.6 and I have been looking at the manual and still struggling. I would appreciate your feedback and your assistance.

Module sourceModule = current
Module targetModule = module("Target Module Name") 
Module linkModule = module("Link Module Name") 
//search phrase inside the attribute text ending with more than one digit numbers 
Regexp reOneSys = regexp "ONE_SYS\_\[0-9\]{2,}"
// Create a Skip list to store target module's "Original ID" and corresponding objects
Skip targetIDs = create()
for Object trgObj in targetModule do {
    string originalID = trgObj."Original ID"
    if (!null originalID) {
        put(targetIDs, originalID, trgObj)
    }
}
int createdLinks = 0
// Iterate through source module objects
for Object srcObj in sourceModule do {
    string sysReq = srcObj."System Req"
    if (!null sysReq) {
        // Find all matches of "ONE_SYS\_" pattern in the System Req
        int startPos = 0
        while (reOneSys sysReq\[startPos:\]) {
            string matchedID = sysReq\[match 0\]
            
            // Look for the matched ID in the target module
            Object trgObj
            if (find(targetIDs, matchedID, trgObj)) {
                // Create link if it doesn't exist
                if (!exists(srcObj-\>linkModule-\>trgObj)) {
                    srcObj-\>linkModule-\>trgObj
                    createdLinks++
                }
            }
            startPos = end 0 + startPos
        }
    }
}
// Print results to DOORS database window
print "Process completed. " createdLinks " links created.\\n"

The problem and what I have tried so far are mentioned.


Solution

  • you were quite close to the solution. There were mainly just some syntax problems.

    See the changes and comments below:

    // "exists" does not exist for Links. use an auxiliary function
    bool doesLinkExist (Object src, string lmName, Object trg) {
        Link l
        bool retval = false
        for l in src->lmName do {
            if target (l) == trg then retval = true
        }
        return retval
    }
    
    Module sourceModule = current
    Module targetModule = edit("Target Module Name", true, true)  // use "edit"
    string linkModuleName = "Link Module Name" // links are created using the name of a module, not the module handle  
    //search phrase inside the attribute text ending with more than one digit numbers 
    Regexp reOneSys = regexp2 "ONE_SYS_[0-9][0-9]+" // a) regexp2 instead of regexp, b) {2,} is not supported, c) not sure where all the escape characters stem from, perhaps some copy/paste. I removed them.
    // Create a Skip list to store target module's "Original ID" and corresponding objects
    Skip targetIDs = create()
    Object trgObj // first declare a variable, then use it
    for trgObj in targetModule do {
        string originalID = trgObj."Original ID"
        if (!null originalID) {
            put(targetIDs, originalID, trgObj)
        }
    }
    int createdLinks = 0
    // Iterate through source module objects
    Object srcObj
    for srcObj in sourceModule do {
        string sysReq = srcObj."System Req"
        if (!null sysReq) {
            // Find all matches of "ONE_SYS_" pattern in the System Req
            int startPos = 0
            while (reOneSys sysReq[startPos:]) {  
                string matchedID = sysReq[match 0]
                
                // Look for the matched ID in the target module
                Object trgObj
                if (find(targetIDs, matchedID, trgObj)) {
                    // Create link if it doesn't exist
                    if (!doesLinkExist(srcObj, linkModuleName, trgObj)) {
                        srcObj->linkModuleName->trgObj
                        createdLinks++
                    }
                }
                startPos = end 0 + startPos
            }
        }
    }
    // Print results to DOORS database window
    print "Process completed. " createdLinks " links created.\\n"