04-15-2013 01:08 PM
Hello,
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.
If I try "Update Property" but got an object is null exception and nuxeo was in a right mess.
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"]:""}
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 ?
thanks
04-17-2013 09:22 AM
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: http://doc.nuxeo.com/pages/viewpage.action?pageId=2392665
06-14-2013 12:02 PM
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);
@Context
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;
@Context
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("")){
@SuppressWarnings("unchecked")
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);
blobDocument.setPropertyValue(Constantes.XPATH_FILENAME,(Serializable)FileUtils.getCleanFileName(blob.getFilename()));
if(titleDocument != null && !titleDocument.equals("")){
blobDocument.setPropertyValue(Constantes.XPATH_TITLE, titleDocument);
}
try {
blobDocument.setPathInfo(input.getPathAsString(),Framework.getService(PathSegmentService.class).generatePathSegment(blobDocument));
session.createDocument(blobDocument);
} catch (Exception e) {
throw new RuntimeException("Runtime: "+e);
}
}
}
else
{
log.warn("workflowVar o typeDocument estan vacios o nulos SaveBlobToInputDocument");
}
return input;
}
}
06-14-2013 12:35 PM
thanks, that's great!
06-14-2013 12:40 PM
Think to check the answers that what useful for you
06-14-2013 12:45 PM
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
06-14-2013 01:03 PM
please create a new question for a new question.
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.