ibm-doors

How to append values into a DOORS attribute using DXL


I would like to add the values from a buffer into a DOORS attribute #Fruits (Attribute type: Text).

  1. The buffer content is updated every time with a for loop. -> Works
  2. Buffer content is inserted into the attribute #Fruits. -> Works
  3. Buffer content is refreshed and gets a new value. -> Works
  4. New Value needs to be appended in the #Fruits attribute without deleting the previous one. -> Does not work!

Ideally I expect that the currently selected Object in #Fruits attribute should contain

Apple
Banana
Pear
Strawberry

However, I get

Strawberry 

(Seems like the content is overwritten.)

Here is what I have tried:

Module m = current
Object o = current
Column col
int nCol = 0
string str = ""

//Check whether #Fruits already exists, if yes, then delete the old one
void DeleteDOORSAttribute(string AttributeName){
    AttrDef ad
    ad = find(m,AttributeName)
    if (null ad){
        print "Creating new attribute #Fruits...\n"
    }
    else{
        delete(m, ad)
        print "Attribute #Fruits already exists\n"
    }
}
DeleteDOORSAttribute("#Fruits")

// Create a new atrribute named as #Fruits
for col in m do{
    nCol++
}
create object type "Text" attribute "#Fruits"
attribute(column nCol, "#Fruits")


//Create an array with fruit names
Array ListOfFruits = create(3,1)
put(ListOfFruits, "Apple", 0, 1)
put(ListOfFruits, "Banana", 1, 1)
put(ListOfFruits, "Pear", 2, 1)
put(ListOfFruits, "Strawberry", 3, 1)

for (x = 0; x < 4; x++){
    str = (string get(ListOfFruits,x,1))
    Buffer buf = create()
    buf += str
    print "buffer content: " buf "\n"
    // Go on the currently selected object and append the fruit names in it
    o."#Fruits" = buf ""    
}

Solution

  • Your loop basically says:

    There is no "append" in your code.

    You could for example create a new line directly after Buffer buf = create() which says buf += o."#Fruits", i.e. take the current content of the attribute, and only afterwards append the Banana to the Apple.

    Or you could move the create statement outside the loop.

    By the way: never create a buffer without deleting it after usage, or else it might eat up all your RAM if you have lots of data.