Change attribute value when attribute name is a parameter

0
I have a very wide entity (100+ attributes) of string attributes. I am changing one attribute at a time in a given object. I need an activity which takes three parameters: object, name of the attribute as string, and value of the attribute as string, and executes the update. In theory, I can create a microflow with 100+ “if” statements to update the individual attribute. I am curious if anybody faced similar problem and wrote a Java action to perform this task, and made it available in app store?
asked
2 answers
1

A simple way to avoid 100+ if statements and very performant is  this:

  1. Create an enumeration with all those attribute names as key-fields.
  1. In your microflow create an enumeration-object based on the attribute name. Do this by calling CommunityCommons/EnumerationFromString, or do as Bart Rikers suggested to my question https://forum.mendix.com/link/questions/102428
  1. Use a decision with that enumeration object.

You will still need a single change-activity for each separate attribute change, but it is fast and mainly Mendix.

answered
0

My extra wide entity contains attributes of five types: string, long, boolean, date, decimal. I can put logic telling the data type inside the microflow and then built 5 Java actions along the following lines: 

public class SetDateValue extends CustomJavaAction<java.lang.String>
{
	private IMendixObject EntityObject;
	private java.lang.String AttributeName;
	private java.util.Date AttributeValue;

	public SetDateValue(IContext context, IMendixObject EntityObject, java.lang.String AttributeName, java.util.Date AttributeValue)
	{
		super(context);
		this.EntityObject = EntityObject;
		this.AttributeName = AttributeName;
		this.AttributeValue = AttributeValue;
	}

	@java.lang.Override
	public java.lang.String executeAction() throws Exception
	{
		// BEGIN USER CODE
		EntityObject.setValue(getContext(), AttributeName, AttributeValue);
                return "Success";
		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 */
	@java.lang.Override
	public java.lang.String toString()
	{
		return "SetDateValue";
	}

	// BEGIN EXTRA CODE
	// END EXTRA CODE
}

 

answered