0

I'm trying to dynamically populate an attribute enumerated list based on another attributes values in IBM DOORS.

the image represent the list of items defined as object text

I want to dynamically update type enum based on the list captured in the picture as "Configuration Item 1", "Configuration Item 2"...

The user add/update a configuration item, then a previously defined enumurated type gets automatically updated with the same addition/update.

Hannibal
  • 1
  • 2

1 Answers1

0

sure, it's possible. Basically you need to define several arrays, among them are

  • names aka codes, i.e. the entry you see
  • values i.e. the integer number assigned with the entry
  • colours i.e. the associated colors with the value
  • optionally a replacement map which defines how existing values shall be migrated to the new definition (i.e. how to migrate "red, green, yellow" to "madder, crimson, pink, lemon, pear, olive, jade, malachit, mantis")

and with these arrays you use perm AttrType modify(AttrType at, string name, [string codes[], int values[], int colors[], string descs[] string URI[], [int arrMaps[],]] string &errMess) command on attribute types. Attached is a script from our library that copies enumerations from one module to another - this might be helpful as a starting point for your script. Also, there's an example how to modify attribute types in the DXL Reference manual, look for "modify(attribute type)" in the chapter "Attribute Type manipulation"

void updateEnumeration__(AttrType sat, at, Module targm)
//    AttrType sat,           // IN: original (source) type
//    AttrType at,            // IN: copy (target) type, null if none exists yet
//    Module targm)           // IN: target module
//
// DESCRIPTION: Creates a copy of the type sat in the target module targm.
//              If a copy already exists ('at'), it is updated.  Any enumerations
//              which are in the copy and have been removed from the source type
//              are kept in the copy, to prevent errors in reading attribute
//              values which use these enumerations in the target module.
{
    string errmess = ""
    int enumerationSize = sat.size
    int index, oldIndex

    if (!null at)
    {
        // Work out the size of the merged enumerations list    
        for (oldIndex = 0; oldIndex < at.size; oldIndex++)
        {
            if (matchIndex(at.strings[oldIndex], sat) == -1)
            {
                // Add one for each old name which isn't used
                enumerationSize++
            }
        }
    }
    
    string enumNames[enumerationSize]
    int enumValues[enumerationSize]
    int enumCols[enumerationSize]
    
    Module savedModule = current

    current = targm

    bool bRealColours = getRealColorOptionForTypes()
    setRealColorOptionForTypes(true)
    
    for (index = 0; index < sat.size; index++) 
    {
        enumNames[index] = sat.strings[index]
        enumValues[index] = sat.values[index]
        enumCols[index] = sat.colours[index]
    }

    if (null at)
    {
        at = create(sat.name "", enumNames, enumValues, enumCols, errmess)
        if (errmess != "") 
        {
            reportError("typeError", "Cannot create attribute type " (sat.name "") " : " errmess);
        }
    }
    else
    {
        // Add any unused old enumerations to the end of the merged list
        oldIndex = 0
        while (index < enumerationSize)
        {
            // Skip enumerations which are still used
            while (matchIndex(at.strings[oldIndex],sat) != -1)
            {
                oldIndex++
            }
            // copy the next unmatched old enumeration
            enumNames[index] = at.strings[oldIndex]
            enumValues[index] = at.values[oldIndex]
            enumCols[index] = at.colours[oldIndex]
            oldIndex++
            index++
        }
        
        // Populate the index mapping array
        int enumOldIndices[enumerationSize]
        for (index = 0; index < enumerationSize; index++)
        {
            enumOldIndices[index] = matchIndex(enumNames[index],at)
        }
        
        // Ready to go: update the type definition...
        modify(at, sat.name "", enumNames, enumValues, enumCols, enumOldIndices, errmess)
        if (errmess != "") 
        {
            reportError("typeError", "Cannot modify attribute type " (sat.name "") " : " errmess);
        }
    }

    setRealColorOptionForTypes(bRealColours)
    current = savedModule 
    
} // updateEnumeration__
Mike
  • 2,098
  • 1
  • 11
  • 18
  • P.S:: that script that you write should not automatically roll out all the changes to all the modules of your database e.g. with a config module save trigger, but you should possibly create a script like "rollout data model to project(s)" which is started by a person / admin who knows about the implications (locked modules, enough access rights to modify the attribute types and objects, time needed for rollout (don't run into a backup) etc.) – Mike Oct 16 '22 at 08:16