Nice question. You can create a java action (input any object and result Decimal) for that purpose and replace the code between //BEGIN USER CODE and // END USER CODE with
// BEGIN USER CODE
Map<String, ? extends IMendixObjectMember<?>> members = anyobject.getMembers(getContext());
int totalcount = 0;
int filledcount = 0;
for(String key : members.keySet()) {
IMendixObjectMember<?> m = members.get(key);
if (!m.isVirtual()) {
totalcount++;
if (m instanceof MendixString) {
String s = (String) m.getValue(getContext());
if (s != null && !s.isEmpty()) {
filledcount++;
}
} else {
if (m.getValue(getContext()) != null) {
filledcount++;
}
}
}
}
if (totalcount > 0) {
return new BigDecimal (Math.round(1000.0 * filledcount / totalcount)/ 1000.0);
}
return new BigDecimal(0);
// END USER CODE
and add this to import (on top)
import java.math.BigDecimal;
import java.util.Map;
import com.mendix.core.objectmanagement.member.MendixString;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import com.mendix.systemwideinterfaces.core.IMendixObjectMember;
You still have to program the exclusion of the 'progress' attribute yourself.
As far as I know there is no out of the box way of doing such in Mendix.
But it can be achieved using a custom JAVA action.
This post might help you to get started: https://stackoverflow.com/questions/36912914/count-non-null-fields-in-an-object
Hi Chris
Thank you for the incredibly detailed explanation. I'm still failing to deploy your solution (first custom java action in Mendix ever, and I'm no java developer).
I have tried following the tutorial: https://docs.mendix.com/howto/logic-business-rules/extending-your-application-with-custom-java, but I'm getting errors in both, Eclipse and of course Mendix when trying to run the action in a Microflow.
These are my current settings (surely I'm missing something obvious somewhere):
Java Action
Eclipse:
Mendix Microflow (just for testing the output: