How do I set the value of an enum attribute when creating / changing an object?

0
I'd like to use enums for the values of finite fields (e.g. status = {'not started', 'in progress', 'complete'}. I have figured out that I access the value as a string through getCaption, but how do I set a value? When I create an object witn an enum attribute, I may want to set it's value in the microflow; same for a process that may wish to change it. I can't put 'complete' or 1 into the Value box as it expects something of type enum. Seems like there should be a getEnumByCaption type of function. I'm hoping that the answer is not to write one microflow for each enum that accepts a string parameter and then iterates through the enum to find the correct one...
asked
2 answers
2

Hi Rob,

  You are correct that tou can't set the value by simply typing 'complete.'  The way to reference enumerations is through referencing the enumeration value in the following way through the equation dialogue:

   <module>.<enumarationName>.<EnumerationValue>

 

For example, pretend I had an enumeration 'RegistrationStatus' for my object 'Registration' that lived in my 'Workflow' module.  If I wanted to set it to 'Complete,'  I would use a change activity on the Status attribute using the following reference:

Workflow.RegistrationStatus.Complete

If you hit 'Ctrl' + 'Space' while using the dialogue box you can find this more easily.

To further get into this, let's look at the use case where you have a String field 'statusString' and want to translate it into an enumeration, you will need some logic in your change activity that looks like this:

if $statusString = 'Complete' then

Workflow.RegistrationStatus.Complete

else if $statusString = 'Not Started' then

Workflow.RegistrationStatus.NotStarted

else if$statusString = 'in progress' then

Workflow.RegistrationStatus.InProgress

 

Hope this helps!

Rob


 

answered
1

Although I agree with Rob as the best way, you technically could set the value by just setting it equal to string value x, where it would look like RegistrationStatus = 'Complete'. It will work but it is hard coded and if you change the caption values of the enum, this method won't update. So while it works I would use what Rob posted and I just wanted you to be aware of this example.

answered