Combine values in multi-value attribute

How would one go about combining the values of a multi-value attribute? For instance, I have an attribute called "Affected Modules" that is a multi-value enumeration. I am wanting to combine the values of this attribute from two different objects into the Affected Modules attribute of a single object. How would one go about doing this?

Thanks


CMusicFan - Wed Mar 26 12:36:21 EDT 2014

Re: Combine values in multi-value attribute
GregM_dxler - Thu Mar 27 09:10:19 EDT 2014

Hi,

For a multivalue enumeration, you use the += operator to add values to it.  So say you want to combine attribute Attr1 and Attr2 into attribute Affected Modules:

o."Affected Modules" += o."Attr1"

o."Affected Modules" += o."Attr2"

That should add the values.  If you wanted to use a different object, then you would replace the appropriate o.

Hope this helps,

Greg

 

Re: Combine values in multi-value attribute
CMusicFan - Thu Mar 27 09:21:58 EDT 2014

GregM_dxler - Thu Mar 27 09:10:19 EDT 2014

Hi,

For a multivalue enumeration, you use the += operator to add values to it.  So say you want to combine attribute Attr1 and Attr2 into attribute Affected Modules:

o."Affected Modules" += o."Attr1"

o."Affected Modules" += o."Attr2"

That should add the values.  If you wanted to use a different object, then you would replace the appropriate o.

Hope this helps,

Greg

 

I must have been unclear about exactly what I am asking. I have two objects, we will call them obj1 and obj2. They both have an  "Affected Modules" attribute with multiple values selected. I am wanting to add all of the selected "Affected Modules" from both obj1 and obj2  together into a single "Affected Modules" attribute (ideally the one for obj1). If I try to use the method you described above, it looks like this

o."Affected Modules" += obj."Affected Modules"

Unfortunately, DOORS returns an an incorrect arguments error  for the += sign with this syntax. I double checked my spelling, so I know it has to be the way I am trying to combine attributes. Is there a good way to do this?

Thanks

Re: Combine values in multi-value attribute
GregM_dxler - Thu Mar 27 10:31:41 EDT 2014

CMusicFan - Thu Mar 27 09:21:58 EDT 2014

I must have been unclear about exactly what I am asking. I have two objects, we will call them obj1 and obj2. They both have an  "Affected Modules" attribute with multiple values selected. I am wanting to add all of the selected "Affected Modules" from both obj1 and obj2  together into a single "Affected Modules" attribute (ideally the one for obj1). If I try to use the method you described above, it looks like this

o."Affected Modules" += obj."Affected Modules"

Unfortunately, DOORS returns an an incorrect arguments error  for the += sign with this syntax. I double checked my spelling, so I know it has to be the way I am trying to combine attributes. Is there a good way to do this?

Thanks

The assignment only works for adding a single value to the multi-value enumeration.  So if the obj2 attribute has more than one value, it won't work.  What you have to do is to check if obj2 has a value set and if so, add it to your obj1.  This code snippit might help

AttrDef adCur
AttrType atCur
int iCount, iEnums    
Module curmod = current
string sAttrName = "Program Specific"
Object o = current
Object oNext = next o

adCur = find(curmod, sAttrName) //get the attribute definition of the selected attribute
atCur = find(curmod, adCur.typeName) //get the attribute type

iEnums = atCur.size //get total number of enumeration values in attribute
string sEnumList[iEnums + 1] //make a string array one larger than total number to make sure it is big enough??
for (iCount = 0; iCount < iEnums; iCount++) {  //now loop through and insert all the new enumeration values
   sEnumList[iCount] = atCur.strings[iCount]
}

for (iCount = 0; iCount < iEnums; iCount++) { //loop through the values
   if (isMember(oNext.sAttrName,sEnumList[iCount])){ //check if next object has that value
      o.sAttrName += sEnumList[iCount] //yes it does, so add it to current object
   }
}

 

Re: Combine values in multi-value attribute
CMusicFan - Thu Mar 27 12:04:29 EDT 2014

GregM_dxler - Thu Mar 27 10:31:41 EDT 2014

The assignment only works for adding a single value to the multi-value enumeration.  So if the obj2 attribute has more than one value, it won't work.  What you have to do is to check if obj2 has a value set and if so, add it to your obj1.  This code snippit might help

AttrDef adCur
AttrType atCur
int iCount, iEnums    
Module curmod = current
string sAttrName = "Program Specific"
Object o = current
Object oNext = next o

adCur = find(curmod, sAttrName) //get the attribute definition of the selected attribute
atCur = find(curmod, adCur.typeName) //get the attribute type

iEnums = atCur.size //get total number of enumeration values in attribute
string sEnumList[iEnums + 1] //make a string array one larger than total number to make sure it is big enough??
for (iCount = 0; iCount < iEnums; iCount++) {  //now loop through and insert all the new enumeration values
   sEnumList[iCount] = atCur.strings[iCount]
}

for (iCount = 0; iCount < iEnums; iCount++) { //loop through the values
   if (isMember(oNext.sAttrName,sEnumList[iCount])){ //check if next object has that value
      o.sAttrName += sEnumList[iCount] //yes it does, so add it to current object
   }
}

 

I found a good way to do it! Here's the code I ended up using.

AttrType ModulesType = find(()current Module), NLS_("Modules"))

// Combine the Affected Modules attributes into the current object
for (i = 0; i < ModulesType.size; i++)
{
    // If the second object includes the current enumeration but the first one does not, add it to the first one
    if (isMember(obj."Affected Modules", ModulesType.strings[i]))
    {
        if (!isMember(o."Affected Modules", ModulesType.strings[i]))
        {
            o."Affected Modules" += ModulesType.strings[i]
        }
    }   
}

I hope this helps someone later on. Feel free to use it!

Thanks for the help!