จะดึงข้อมูลตัวแปรได้อย่างไรหลังจากการประมวลผลเวิร์กโฟลว์เสร็จสิ้นใน camunda?

ฉันกำลังพยายามตั้งค่าตัวแปรระหว่างการดำเนินการเวิร์กโฟลว์หลังจากเสร็จสิ้นแล้ว

การสร้างอินสแตนซ์เวิร์กโฟลว์ในคลาส WorkflowStart จากนั้นดึงค่า

ProcessInstance pi = runtimeService.startProcessInstanceByKey("workflowName");
System.out.println("runtimeService.getVariables(getId()) "+runtimeService.getVariables(pi.getId()));   

คำสั่งข้างต้นเริ่มเวิร์กโฟลว์และดำเนินการทั้งหมด ดังนั้นเมื่อฉันเขียน

 public class FlowDelegate  implements JavaDelegate {
    public void execute(DelegateExecution execution) throws Exception {
        execution.setVariable("abc123", "123");
        System.out.println("Execution variables - "+execution.getVariables());      
 }
}

พิมพ์บรรทัดด้านบน

{
  abc123 => Value '123' of type 'PrimitiveValueType[string]'
}

ดังนั้นหลังจาก processInstance รันเวิร์กโฟลว์และพยายามเข้าถึงตัวแปร ฉันจะได้รับการติดตามสแต็กนี้

และดำเนินการ

 System.out.println("runtimeService.getVariables(getId()) "+runtimeService.getVariables(pi.getId()));


ENGINE-16004 Exception while closing command context: execution e575eb8b-7b84-11e8-a237-54e1ad4a38ce doesn't exist: execution is null
 org.camunda.bpm.engine.exception.NullValueException: execution e575eb8b-7b84-11e8-a237-54e1ad4a38ce doesn't exist: execution is null

person surbhi bakshi    schedule 29.06.2018    source แหล่งที่มา


คำตอบ (1)


เมื่อกระบวนการเสร็จสิ้น จะไม่สามารถเข้าถึงได้ผ่านรันไทม์ API อีกต่อไป คุณสามารถใช้ได้. HistoryService#createHistoricVariableInstanceQuery เพื่อเข้าถึงค่า

อัปเดต: ในขณะเดียวกัน camunda รองรับค่าส่งคืนสำหรับการเริ่มต้นกระบวนการ คุณสามารถใช้ RuntimeService.html#createProcessInstanceById จากนั้น executeWithVariablesInReturn() เพื่อรับตัวแปรของทันที อินสแตนซ์เริ่มต้น โดยไม่จำเป็นต้องมีแบบสอบถามเพิ่มเติม (แพง) เกี่ยวกับตัวแปรในอดีต

person Jan Galinski    schedule 30.06.2018