Getting workflow input using workflow Id in java

Hi

I want to fetch input data of the workflow using workflow id and runId in java. How can i achieve this?

One way of doing it is by fetching event history for this execution and getting WorkflowExecutionStartedEventAttributes from first event in history (WorkflowExecutionStarted event), something like

WorkflowExecutionHistory history = client.fetchHistory(workflowId, runId);
Payloads payloads =
    history.getHistory().getEvents(0).getWorkflowExecutionStartedEventAttributes().getInput();
for (Payload payload : payloads.getPayloadsList()) {
     // using default data converter..assumes string type
     // note if you use custom data converter you would need use it instead of default
     String input = DefaultDataConverter.newDefaultInstance()
              .fromPayload(payload, String.class, String.class);
}
1 Like