ListWorkflow results to include parent workflow ID

Hi,

Is there a way to include information on the parent workflow (workflow ID would be enough, here) when listing workflows via the ListWorkflow client API method?
The Go SDK returns a slice of WorkflowExecutionInfo objects that already have a GetParentExecution() method. However, that always seems to be empty.

Thank you very much in advance.

Cheers,
Daniel

Hi @danieljoos

maybe you can use Memo , which is returned as part of WorkflowExecutionInfo

Let me know if it helps
Antonio

Thank you.
Memo sounds really promising. I’ll try that.

Cheers
Daniel

Using a Memo field works like a charm.
I’ve created a WorkflowOutboundInterceptor that will automatically set the field on every call to ExecuteChildWorkflow.

Something like this:

type parentWorkflowIDWorkerInterceptor struct {
	interceptor.WorkerInterceptorBase
}

type parentWorkflowIDInboundInterceptor struct {
	interceptor.WorkflowInboundInterceptorBase
}

type parentWorkflowIDOutboundInterceptor struct {
	interceptor.WorkflowOutboundInterceptorBase
}

var _ interceptor.WorkerInterceptor = (*parentWorkflowIDWorkerInterceptor)(nil)
var _ interceptor.WorkflowInboundInterceptor = (*parentWorkflowIDInboundInterceptor)(nil)
var _ interceptor.WorkflowOutboundInterceptor = (*parentWorkflowIDOutboundInterceptor)(nil)

// NewParentWorkflowIDInterceptor returns a new Temporal workflow interceptor that sets the parent workflow ID
// when executing child workflows. The parent workflow ID is stored in the child workflow options memo.
func NewParentWorkflowIDInterceptor() interceptor.WorkerInterceptor {
	return &parentWorkflowIDWorkerInterceptor{}
}

func (wi *parentWorkflowIDWorkerInterceptor) InterceptWorkflow(ctx workflow.Context, next interceptor.WorkflowInboundInterceptor) interceptor.WorkflowInboundInterceptor {
	i := &parentWorkflowIDInboundInterceptor{}
	i.Next = next
	return i
}

func (wi *parentWorkflowIDInboundInterceptor) Init(outbound interceptor.WorkflowOutboundInterceptor) error {
	i := &parentWorkflowIDOutboundInterceptor{}
	i.Next = outbound
	return wi.Next.Init(i)
}

// ExecuteChildWorkflow intercepts the execution of a child workflow and sets the parent workflow ID in
// a memo field of the child workflow options. This way it can be accessed when listing workflows.
func (wi *parentWorkflowIDOutboundInterceptor) ExecuteChildWorkflow(ctx workflow.Context, childWorkflowType string, args ...interface{}) workflow.ChildWorkflowFuture {
	// Get the current workflow ID and store it into the child options memo.
	workflowID := workflow.GetInfo(ctx).WorkflowExecution.ID
	opts := workflow.GetChildWorkflowOptions(ctx)
	if opts.Memo == nil {
		opts.Memo = map[string]interface{}{}
	}
	opts.Memo["parent-workflow-id"] = workflowID
	// Continue to execute the child workflow with the changed options.
	ctx = workflow.WithChildOptions(ctx, opts)
	return wi.Next.ExecuteChildWorkflow(ctx, childWorkflowType, args...)
}