Check https://forum.mendix.com/link/questions/90433
Created from answers on the forum (use search):
create java action with a param level to get the calling mf or current mf
// BEGIN USER CODE
int intLevel = level != null ? level.intValue() : 1;
IContext context = this.getContext();
Stack<CoreAction<?>> coreAction;
CoreAction<?> nthCoreAction;
String microflowName = "";
if (context!=null){
Core.getLogger(this.toString()).trace("Context exists");
coreAction = context.getActionStack();
if (coreAction!=null){
int actionStackSize = coreAction.size();
Core.getLogger(this.toString()).trace("coreAction exists with size: " + actionStackSize);
// determine the level to get the stackaction from. The actionStack contains all levels of microflows currently active, so also all sublevels.
int Level = (actionStackSize - intLevel) - 1;
// make sure the ArrayIndexOutOfBounds exception can't occur
if ((Level >= 0) && (Level < actionStackSize)){
Core.getLogger(this.toString()).trace("get on " + Level + " nth element");
nthCoreAction = coreAction.get(Level);
if (nthCoreAction!=null){
Core.getLogger(this.toString()).trace("nthCoreAction exists with name " + nthCoreAction.getMetaInfo().toString());
microflowName = nthCoreAction.getActionName();
}
}
}
}
return microflowName;
// END USER CODE
😎
Arthur,
This code to retrieve MFname (e.g. SolarEdge_API.ACT_Energy_hour_refresh) is still working in Mx 9.3.0:
// BEGIN USER CODE
IContext c = this.getContext();
// Get the Stack of actions.
Stack<ICoreAction<?>> stack = c.getActionStack();
try {
/*
* The current action is located the second to last element.
* -1 for the last element that is empty / has no name.
* -1 for the fact that the index starts at 0.
*/
ICoreAction<?> action = stack.elementAt(stack.size()-2);
return action.getActionName();
} catch (IndexOutOfBoundsException e){
Core.getLogger("GetCurrentFQMicroflowName").error(e.getClass().toString() + ": " +e.getMessage());
return null;
}