public VariableInstance setVariableInstance ( Long procInstId , String name , Object value ) throws DataAccessException { TransactionWrapper transaction = null ; EngineDataAccessDB edao = new EngineDataAccessDB ( ) ; try { transaction = edao . startTransaction ( ) ; VariableInstance varInst = edao . getVariableInstance ( procInstId , name ) ; if ( varInst != null ) { if ( value instanceof String ) varInst . setStringValue ( ( String ) value ) ; else varInst . setData ( value ) ; edao . updateVariableInstance ( varInst ) ; } else { if ( value != null ) { ProcessInstance procInst = edao . getProcessInstance ( procInstId ) ; Process process = null ; if ( procInst . getProcessInstDefId ( ) > 0L ) process = ProcessCache . getProcessInstanceDefiniton ( procInst . getProcessId ( ) , procInst . getProcessInstDefId ( ) ) ; if ( process == null ) process = ProcessCache . getProcess ( procInst . getProcessId ( ) ) ; Variable variable = process . getVariable ( name ) ; if ( variable == null ) { throw new DataAccessException ( "Variable " + name + " is not defined for process " + process . getId ( ) ) ; } varInst = new VariableInstance ( ) ; varInst . setName ( name ) ; varInst . setVariableId ( variable . getId ( ) ) ; varInst . setType ( variable . getType ( ) ) ; if ( value instanceof String ) varInst . setStringValue ( ( String ) value ) ; else varInst . setData ( value ) ; edao . createVariableInstance ( varInst , procInstId ) ; } else varInst = null ; } return varInst ; } catch ( SQLException e ) { throw new DataAccessException ( - 1 , "Failed to set variable value" , e ) ; } finally { edao . stopTransaction ( transaction ) ; } }
create or update variable instance value . This does not take care of checking for embedded processes . For document variables the value must be DocumentReference not the document content