Automation Chain + setproperty + NOT mandatory Blob : Set Document BLOB properties with workflow var but got null problem


I want to set a Document var of type blob with a workflow var, in an automation chain, after selection of this var in a workflow form.

This workflow var is not mandatory and that is the problem.

1) If I try “Update Property” but got an object is null exception and nuxeo was in a right mess.

2) I try to set this variable with a condition like setting workflow var, But nuxeo tells me that the update properties only allow “scalar”…

@{WorkflowVariables["wkToto"] != null?WorkflowVariables["wkToto"]:""}

3) So I try “run script” but I couldn't get the “current document”… :-(

if (WorkflowVariables["wkToto"]  != null){
Document.doc.setPropertyValue("amoi:toto",WorkflowVariables["wkToto"]) ;

Do you know how to SET a document BLOB even if it's NULL with workflow var ?


1 votes

2 answers



I did a custom operation save blob from workflow to document attached to workflow in my nuxeo ide and sent it to studio

@Operation(id=SaveBlobToInputDocument.ID, category=Constants.CAT_SERVICES, label="SaveBlobToInputDocument", description="Guarda blob en el inputdocument. Usar esta cadena solo en documentos con workflows activos")
public class SaveBlobToInputDocument {

    public static final String ID = "SaveBlobToInputDocument";
    private static final Log log = LogFactory.getLog(SaveBlobToInputDocument.class);
    protected CoreSession session;

    @Param(name = "workflow_var", required = true)
    protected String workflowVar;

    @Param(name = "type_document", required = true)
    protected String typeDocument;

    @Param(name = "title_document", required = false)
    protected String titleDocument; 

    protected OperationContext ctx; 

    @OperationMethod(collector = DocumentModelCollector.class)  
    public DocumentModel run(DocumentModel input) throws ClientException  {
        if(workflowVar != null && !workflowVar.trim().equals("")&& typeDocument!= null && !typeDocument.trim().equals("")){
            Object obj =((Map<String, Serializable>)ctx.get(Constants.VAR_WORKFLOW)).get(workflowVar);                          
            if (obj != null && obj instanceof Blob){                    
                Blob blob= (Blob) obj;
                DocumentModel blobDocument = session.createDocumentModel(typeDocument);
                blobDocument.setPropertyValue(Constantes.XPATH_FILECONTENT,(Serializable) blob);
                if(titleDocument != null && !titleDocument.equals("")){
                    blobDocument.setPropertyValue(Constantes.XPATH_TITLE, titleDocument);   
                try {
                } catch (Exception e) {
                    throw new RuntimeException("Runtime: "+e);
            log.warn("workflowVar o typeDocument estan vacios o nulos SaveBlobToInputDocument");
        return input;
0 votes

thanks, that's great!

Think to check the answers that what useful for you

I also would like to know when my answer has errors or if there is a better way to do that. Thanks. I only want to help

please create a new question for a new question.

Hello Me,

I don't know why the basic “update property” don't work with blob…

Nevertheless, this is the answer:

Automation Chain:

  • Document is in input.

  • Do A Run Script

    if (WorkflowVariables[“varamoiwk”] != null){ Document.doc.setPropertyValue(“monxpath:mavalaupdate”,WorkflowVariables[“varamoiwk”]) ; }

  • Do A “Document Save” (This was missing ;-) )

This is an exemple of an other Run Script:

0 votes