cancel
Showing results for 
Search instead for 
Did you mean: 

How to update programmatically workflow variable after create it

geekonspace
Star Contributor
Star Contributor

I'm starting a workflow programmatically and want to save the id of the newly created route document in a variable in my workflow. I have done this:

String workflowId = startWorkflow(workflowName,list,map); //my custom method returns workflowId
DocumentModel doc = documentManager.getDocument(new IdRef(workflowId));
GraphRoute route= doc.getAdapter(GraphRoute.class);
Map<String, Serializable> mapRoute = route.getVariables();                
mapRoute.put(BusinessConstantes.DOCUMENT_ROUTE_ID, workflowId);
route.setVariables(mapRoute);  

but in the line where I try to assign the variables (route.setVariables(mapRoute);) the following error is displayed:

Caused by: org.nuxeo.ecm.core.api.DocumentSecurityException: Privilege 'WriteProperties' is not granted to 'boxoffice'
at org.nuxeo.ecm.core.api.AbstractSession.checkPermission (AbstractSession.java: 282)
at org.nuxeo.ecm.core.api.AbstractSession.saveDocument (AbstractSession.java: 1859)
at
... 122 more
Caused by: org.nuxeo.ecm.core.api.ClientRuntimeException: org.nuxeo.ecm.core.api.DocumentSecurityException: Privilege 'WriteProperties' is not granted to 'box office'
at
at org.nuxeo.ecm.platform.routing.core.impl.GraphRouteImpl.setVariables (GraphRouteImpl.java: 139)

User 'boxoffice' is not administrator and he is not assigned to workflow but I want any user can start workflow and also save workflowId in workflow variables.

How Can I do?

1 ACCEPTED ANSWER

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator

Task document and Workflow document are created by the system profile and are hidden for all users. To access to these documents, you have to use UnrestrictedSessionRunner:

public class AddIdInWorkflow extends UnrestrictedSessionRunner {
    private final DocumentModel worflow;
    private final String value;

    public AddIdInWorkflow(CoreSession session,
            DocumentModel worflow, String value) {
        super(session);
        this.worflow = worflow;
        this.value = value;
    }

    @Override
    public void run() throws ClientException {
        worflow.setPropertyValue("myschema:id", value);
        session.saveDocument(workflow);
        session.save();
    }

}

And then to execute the modification:

new AddIdInWorkflow(session, workflow, value).runUnrestricted()

View answer in original post

2 REPLIES 2

Benjamin_Jalon1
Elite Collaborator
Elite Collaborator

Task document and Workflow document are created by the system profile and are hidden for all users. To access to these documents, you have to use UnrestrictedSessionRunner:

public class AddIdInWorkflow extends UnrestrictedSessionRunner {
    private final DocumentModel worflow;
    private final String value;

    public AddIdInWorkflow(CoreSession session,
            DocumentModel worflow, String value) {
        super(session);
        this.worflow = worflow;
        this.value = value;
    }

    @Override
    public void run() throws ClientException {
        worflow.setPropertyValue("myschema:id", value);
        session.saveDocument(workflow);
        session.save();
    }

}

And then to execute the modification:

new AddIdInWorkflow(session, workflow, value).runUnrestricted()

Thanks!!!!

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.