I got this working in a demo project, I'll invite you in a minute. The required Java code is:
// BEGIN USER CODE
HashMap<String, Object> parameters = new HashMap<String, Object>();
parameters.put(inputName, inputObject);
Future<Object> future = Core.executeAsync(this.getContext(), microflowName, false, parameters);
future.get();
return true;
// END USER CODE
Note the false in the Core.executeAsync() method. Without this parameter, this fails.
Ronald:
"Although you may be correct that this will never work (haven't tested yet, should work in my opinion), it is simply plain wrong that NP objects only exist client side: this might be true in Mendix 7, but isn't valid for Mendix 6.9.1.
8 minutes ago"
Think that Rom is correct in this case, even stonger yet it woks in older versions.... i even get the correct objectID in my debugflow... but even when the correct assiciation is present i can't seem to retrieve it.
See used code below:
public static Boolean runMicroflowInBackground(final IContext context, final String microflowName,
final IMendixObject paramObject)
{
final ISession session = context.getSession();
if (paramObject != null)
session.retain(paramObject); // shows as deprecated
MFSerialExecutor.instance().execute(new Runnable() {
@Override
public void run()
{
try
{
IContext c = Core.createSystemContext();
if (paramObject != null) {
//Core.executeAsync(c, microflowName, true, paramObject).get(); //MWE: somehow, it only works with system context... well thats OK for now.
// use context instead of c otherwise there is no currentsession passed
Core.executeAsync(context, microflowName, true, paramObject).get(); //MWE: somehow, it only works with system context... well thats OK for now.
}
else
Core.executeAsync(c, microflowName, true, new HashMap<String,Object>()).get(); //MWE: somehow, it only works with system context... well thats OK for now.
}
catch (Exception e)
{
throw new RuntimeException("Failed to run Async: "+ microflowName + ": " + e.getMessage(), e);
}
finally {
if (paramObject != null)
session.release(paramObject.getId()); // shows as deprecated
}
}
});
return true;
}
I think this will never work with non persistent objects. Non persistent objects only exist client side, so a Java action is never able to pick up these objects. My sollution would be to make them persistable and do a cleanup of these objects later.
Regards,
Ronald