# Parameters for Dynamic Workflows

**URL:** <https://community.temporal.io/t/parameters-for-dynamic-workflows/12213>\
**Category:** Community Support\
**Tags:** go-sdk\
**Created:** [May 23, 2024, 12:49pm UTC](https://community.temporal.io/t/parameters-for-dynamic-workflows/12213 "2024-05-23T12:49:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pseudomuto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pseudomuto/32/5376_2.png) [@pseudomuto](https://community.temporal.io/u/pseudomuto)\
**Post date:** [May 23, 2024, 12:49pm UTC](https://community.temporal.io/t/parameters-for-dynamic-workflows/12213/1 "2024-05-23T12:49:19Z")

</div>

Hey there! I have a use case where I’m trying to supply a parameter (struct) to a dynamic workflow (i.e. ones started with `ExecuteWorkflow(ctx, opts, "WorkflowName", <args>)`).

There is an [example here](https://github.com/temporalio/samples-go/tree/065f2331fafbd9fd335c1d3dc8ebe635a71dace0/dynamic) which shows how to start a workflow by name (as above) but without any arguments.

Essentially, I have something like this:

```auto
type (
    Args struct {
        Prop1 string
        Prop2 string
    }

   Result struct { ... }
)

func MyWorkflow(ctx workflow.Context, args Args) (*Result, error) {
    // implementation here
}

```

I want to be able to launch this (from a CLI in a different repo) using this:

```auto
func main() {
    client, err := ... // create a Temporal client

    client.ExecuteWorkflow(context.Background(), client.StartWorkflowOptions {
        ID: "workflowID",
        "TaskQueue": "work",
    }, "MyWorkflow", "JSON Representation of Args")
}

```

I’ve tried using `converters.JSONPayloadConverter` and just extracting the `Data` field, but no luck.

Has anyone figured out a way to do this?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [May 23, 2024, 4:30pm UTC](https://community.temporal.io/t/parameters-for-dynamic-workflows/12213/2 "2024-05-23T16:30:19Z")

</div>

I don’t think this is supported out of the box. The workaround is to create your own type, “MyJSON,” for example, and then create your own DataConverter for this type.

---

<div class="post-metadata">

**Author:** ![pseudomuto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pseudomuto/32/5376_2.png) [@pseudomuto](https://community.temporal.io/u/pseudomuto)\
**Post date:** [May 23, 2024, 8:07pm UTC](https://community.temporal.io/t/parameters-for-dynamic-workflows/12213/3 "2024-05-23T20:07:47Z")

</div>

Hey @maxim thanks so much for the response!

Would you suggest I create a new wrapper type for all args and then update all of my existing workflows to use this new type as an argument?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [May 24, 2024, 5:23am UTC](https://community.temporal.io/t/parameters-for-dynamic-workflows/12213/4 "2024-05-24T05:23:44Z")

</div>

No, I suggest you create a single type for all raw JSON arguments, something like the “RawJSON” type. It would create output Payload in exactly the same format as JSONPayloadConverter.

---

<div class="post-metadata">

**Author:** ![pseudomuto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pseudomuto/32/5376_2.png) [@pseudomuto](https://community.temporal.io/u/pseudomuto)\
**Post date:** [May 24, 2024, 2:49pm UTC](https://community.temporal.io/t/parameters-for-dynamic-workflows/12213/5 "2024-05-24T14:49:40Z")

</div>

Thank you so much for the pointers @maxim! I was able to get this working using the method you described.

In case anyone else runs into this, here’s what I ended up with:

```auto
package workflows

import (
	"go.temporal.io/api/common/v1"
	"go.temporal.io/sdk/converter"
)

type (
	// Arg represents a dynamic JSON argument. This is encoded as a JSON payload under the hood so that decoding on the
	// temporal worker will be the corresponding arg type for the workflow.
	//
	// It is up to the caller to ensure what's passed in can be decoded server-side.
	Arg struct {
		Json []byte // The raw JSON.
	}

	// A custom payload converter for encoding Args
	payloadConverter struct {
		*converter.JSONPayloadConverter
	}
)

// NewDataConverter returns a composite DataConverter that includes support for encoding Arg objects.
func NewDataConverter() converter.DataConverter {
	return converter.NewCompositeDataConverter(
		converter.NewNilPayloadConverter(),
		converter.NewByteSlicePayloadConverter(),
		converter.NewProtoJSONPayloadConverter(),
		converter.NewProtoPayloadConverter(),
		converter.NewJSONPayloadConverter(),
		&payloadConverter{converter.NewJSONPayloadConverter()},
	)
}

// ToPayload creates a Payload for the bytes within the Arg object.
//
// NB: This returns nil (and no error) when this converter should not be used.
func (p *payloadConverter) ToPayload(v any) (*common.Payload, error) {
	if v, ok := v.(Arg); ok {
		return &common.Payload{
			Metadata: map[string][]byte{
				converter.MetadataEncoding: []byte(p.Encoding()),
			},
			Data: v.Json,
		}, nil
	}

	return nil, nil
}

```

And then when creating the client:

```auto
client, err := client.Dial(client.Options{
	HostPort: "localhost:7233",
	DataConverter: workflows.NewDataConverter(),
	...
})
...
...

```

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [May 24, 2024, 4:39pm UTC](https://community.temporal.io/t/parameters-for-dynamic-workflows/12213/6 "2024-05-24T16:39:30Z")

</div>

I don’t understand how your code works. The converters are evaluated in the order of registration with the composite data converter. So, your custom data converter is never called, as the JSONPayloadConverter would try to serialize the Arg and not give it to the next converter. I think you want to change the order of registration for your custom converter to precede the JSONPayloadConverter. And I would not serialize any other type than Arg and just pass it to the next one.

---

<div class="post-metadata">

**Author:** ![pseudomuto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pseudomuto/32/5376_2.png) [@pseudomuto](https://community.temporal.io/u/pseudomuto)\
**Post date:** [May 24, 2024, 5:40pm UTC](https://community.temporal.io/t/parameters-for-dynamic-workflows/12213/7 "2024-05-24T17:40:10Z")

</div>

That was my understanding as well. However, if I move the custom one anywhere above JSONPayloadConverter, I get `{ "Json": "<value>" }` instead of the custom output.

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [May 24, 2024, 6:05pm UTC](https://community.temporal.io/t/parameters-for-dynamic-workflows/12213/8 "2024-05-24T18:05:47Z")

</div>

I would look at this in the debugger, as this doesn’t make sense.

> <https://github.com/temporalio/sdk-go/blob/f5a0127ce4fe61d332ede903d079c22731d7572f/converter/composite_data_converter.go#L106>
