Hi Ron,
create a java action with name GetLength with following config
use this code
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.
package commentsmodule.actions;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import com.mendix.systemwideinterfaces.core.meta.IMetaObject;
import com.mendix.systemwideinterfaces.core.meta.IMetaPrimitive;
import com.mendix.systemwideinterfaces.core.meta.IMetaPrimitive.PrimitiveType;
import java.util.List;
import java.util.stream.Collectors;
public class GetLength extends CustomJavaAction<java.lang.String>
{
private IMendixObject Entity;
public GetLength(IContext context, IMendixObject Entity)
{
super(context);
this.Entity = Entity;
}
@java.lang.Override
public java.lang.String executeAction() throws Exception
{
// BEGIN USER CODE
IContext context = getContext();
IMetaObject metaObject = Entity.getMetaObject();
List<String> attributesInfo = metaObject.getMetaPrimitives().stream()
.filter(metaPrimitive -> metaPrimitive.getType() == PrimitiveType.String)
.map(metaPrimitive -> {
String attributeName = metaPrimitive.getName();
PrimitiveType attributeType = metaPrimitive.getType();
String typeName = attributeType.toString();
int attributeLength = getDefinedLength(metaPrimitive);
return String.format("%s-%d", attributeName, attributeLength);
})
.collect(Collectors.toList());
return String.join("\n", attributesInfo);
// END USER CODE
}
/**
* Returns a string representation of this action
* @return a string representation of this action
*/
@java.lang.Override
public java.lang.String toString()
{
return "GetLength";
}
// BEGIN EXTRA CODE
private int getDefinedLength(IMetaPrimitive metaPrimitive) {
return metaPrimitive.getLength();
}
// END EXTRA CODE
}
Hope it helps!
You should be able to write a java action that uses this method.
https://apidocs.rnd.mendix.com/9/runtime/com/mendix/systemwideinterfaces/core/meta/IMetaPrimitive.html#getLength()
Take a look at the IMetaObject, you can use this interface to get all sorts of info about a specific entity
https://apidocs.rnd.mendix.com/9/runtime/com/mendix/systemwideinterfaces/core/meta/IMetaObject.html
If you don't want to write your own java action the Model Reflection Module already has this info available
https://marketplace.mendix.com/link/component/69