How Can I solve this problem related to init workflow instances?

Hi, I have designed a workflow in my nuxeo studio : wTest, this workflow has first user task and the assignee property in this task has this value: @{WorkflowVariables["user_assigned"] == "" ? "user_group" : WorkflowVariables["user_assigned"]}, with this configuration, first time the task is assigned to default group “user_group” and if there is a reject, the task is assgined to last user assigned.

I want to create instance but without start it automatically, then I use your method createNewInstance with startInstance parameter in false:

createNewInstance(final String routeModelId,
            final List<String> docIds, final Map<String, Serializable> map,
            CoreSession session, final boolean startInstance)

With the parameter returned, I search documentRoute and using my custom method I want to start the instance, in my method I did this:

protected void startInstance(final DocumentRoute route,
        final Map<String, Serializable> map, CoreSession session) {
    try {
        new UnrestrictedSessionRunner(session) {
            @Override
            public void run() throws ClientException {
                fireEvent(
                        DocumentRoutingConstants.Events.beforeRouteStart
                                .name(),
                        new HashMap<String, Serializable>());
                DocumentRoutingEngineService routingEngine = Framework
                        .getLocalService(DocumentRoutingEngineService.class);
                routingEngine.start(route, map, session);
            }

            protected void fireEvent(String eventName,
                    Map<String, Serializable> eventProperties) {
                eventProperties
                        .put(DocumentRoutingConstants.DOCUMENT_ELEMENT_EVENT_CONTEXT_KEY,
                                route);
                eventProperties.put(
                        DocumentEventContext.CATEGORY_PROPERTY_KEY,
                        DocumentRoutingConstants.ROUTING_CATEGORY);
                DocumentEventContext envContext = new DocumentEventContext(
                        session, session.getPrincipal(),
                        route.getDocument());
                envContext.setProperties(eventProperties);
                EventProducer eventProducer = Framework
                        .getLocalService(EventProducer.class);
                try {
                    eventProducer.fireEvent(envContext.newEvent(eventName));
                } catch (ClientException e) {
                    throw new ClientRuntimeException(e);
                }
            }

        }.runUnrestricted();
    } catch (ClientException e) {
        throw new RuntimeException(e);
    }
}

I believe this is the same thing but in two parts, what happens is that I want create the instance, set a value into map variable before start automatically. Now when I create and start instance automatically with your method createNewInstance, this works perfectly but when I want to create the instance, set value to map and after start it with my method, this error is throws in server log:

Caused by: org.nuxeo.ecm.platform.routing.api.exception.DocumentRouteException: Can not evaluate task assignees from WorkflowVariables["user_assigned"] == "" ? "user_group" : WorkflowVariables["user_assigned"]
    at org.nuxeo.ecm.platform.routing.core.impl.GraphNodeImpl.evaluateTaskAssignees(GraphNodeImpl.java:584)
    at org.nuxeo.ecm.platform.routing.core.impl.GraphRunner.createTask(GraphRunner.java:345)
    at org.nuxeo.ecm.platform.routing.core.impl.GraphRunner.runGraph(GraphRunner.java:228)
    at org.nuxeo.ecm.platform.routing.core.impl.GraphRunner.run(GraphRunner.java:75)

How can I do that?, Create instance, set a value inside of map, start instance and to prevent this error. In another workflows, it works perfectly but the assignes values are statics and not expresions.

0 votes

1 answers

1099 views

ANSWER



Hi, we have replaced our ternary expresion

1-@{WorkflowVariables["user_assigned"] == "" ? "user_group" : WorkflowVariables["user_assigned"]}

with

2-@{WorkflowVariables["user_assigned"] == empty ? "user_group" : WorkflowVariables["user_assigned"]}

Why my old expresion (1) worked perfectly and now with my custom changes, we have to use expression (2)? Resp: We dont know :S

0 votes