How to update programmatically workflow variable after create it

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);

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 ( 282)
at org.nuxeo.ecm.core.api.AbstractSession.saveDocument ( 1859)
... 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 org.nuxeo.ecm.platform.routing.core.impl.GraphRouteImpl.setVariables ( 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?

0 votes

1 answers



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) {
        this.worflow = worflow;
        this.value = value;

    public void run() throws ClientException {
        worflow.setPropertyValue("myschema:id", value);


And then to execute the modification:

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