Convert String to enumeration

0
I want to convert a String variable retrieved from a list of objects to Enumeration in the loop. I need to compare this string variable with another list of enumeration, if the string does not exist as value of the enumeration, i need to remove it from the list.   How can I change the String attribute to Enumeration for comparison.
asked
2 answers
3

I made a small generic java action for this for any enum because javaparameters does not support anyEnum.

📁 download here: https://app.box.com/s/15rexi1r0kjzefc0f29qefvzxkdulm1x

You need to provide a dummy entity with the enum as attribute to parse. It returns false if it cannot find the enum value.

//zoek attribuut in object op basis van enum name:
if ( EnumObject.getMember(this.getContext(), this.EnumName ) != null ) {
	//gevraagde enum bestaat in het aangeleverde object nu opzoeken in metamodel	
	for( IMetaPrimitive metaPrimitive : EnumObject.getMetaObject().getMetaPrimitives() )
	{
		//zoeken op basis van naam en type
		if( metaPrimitive.getType() == PrimitiveType.Enum && metaPrimitive.getName().equals(this.EnumName) )
		{						
		//haal alle waarden van de enum op
			for( IMetaEnumValue metaEnumValue : metaPrimitive.getEnumValues() )
			{
			//als de waarde overeenkomt met je string die je wilt parsen vul dan het aangeleverde object met juiste waarde
				if ( metaEnumValue.getIdentifier().equals(StringToParse) ) 
                {
					EnumObject.setValue(this.context(), EnumName, metaEnumValue.getIdentifier() );
					return true;
				}
			}
		}	
	}
}
return false;

 

answered
0

You can call a sub microflow where you check your string against the caption:

getCaption(ModuleName.EnumerationName.Value) = $YourString

Use a series of exclusive splits checking against each value until you find it, once you find it return the enumeration value and set it in your object.

answered