IBM Doors DXL: Check if Module/Object DataType or Attribute exists

Problem

The existence of DataTypes or Attributes shall be checked

Approach – Ansatz

  • The first function uses the find-function to check for attributes
  • The second uses a loop to check for datatypes

Solution – Lösung

bool attributeExists(Module tgt, string attributeName)
{
	AttrDef ad = find(tgt, attributeName) 
	
	if(null ad)
	{
		return false;
	}
	else
	{
		return true;
	}		
	return false;
}

// This example is done in a different way but works
// here for DataTypes (instead the find function can be used)
bool dataTypeExists(Module tgt, string dataTypeName)
{
	AttrType at;
	
	for at in tgt do 
	{
		if(at.name == dataTypeName)
		{
			return true;
		}
	}	
	
	return false;
}

3 Gedanken zu „IBM Doors DXL: Check if Module/Object DataType or Attribute exists“

  1. To check if an attribute exists in the current module, it is also possible to just do

    if (exists attribute „MyAttributeName“)

      1. Good point!

        Another one: your function attributeExists() doesn’t check if the given attribute could be a module attribute. It only finds object attributes. The DXL manual, example for „for AttrType in ModuleProperties“ gives a solution on how to find those.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.