new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Temporal · all subjects

search attributes

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Default Search Attributes in Temporal

Default Search Attributes like WorkflowType, StartTime and ExecutionStatus are automatically added to Workflow Executions.

Custom Search Attributes creation in Temporal

Custom Search Attributes can contain domain-specific data like customerId or numItems. To create a new Search Attribute in your Temporal Service, use the CLI or Web UI. Example CLI command: temporal operator search-attribute create --name CustomKeywordField --type Text. Custom Search Attribute types include: Text, Keyword, Int, Double, Bool, Datetime, KeywordList.

.NET SDK set Search Attributes on workflow start

To set custom Search Attributes when starting a Workflow, use the TypedSearchAttributes property on WorkflowOptions for StartWorkflowAsync or ExecuteWorkflowAsync. Typed search attributes are a SearchAttributeCollection created with a builder.

.NET SDK custom Search Attributes example

```csharp // This only needs to be created once, so it is common to make it a static readonly even though we // create inline here for demonstration var myKeywordAttributeKey = SearchAttributeKey.CreateKeyword("MyKeywordAttribute"); // Start workflow with the search attribute collection var handle = await client.StartWorkflowAsync( (MyWorkflow wf) => wf.RunAsync(), new(id: "my-workflow-id", taskQueue: "my-task-queue") { TypedSearchAttributes = new SearchAttributeCollection.Builder(). Set(myKeywordAttributeKey, "SomeKeywordValue"). ToSearchAttributeCollection(), }); ``` This example shows how to set custom Search Attributes when starting a Workflow.

.NET SDK UpsertTypedSearchAttributes for updating Search Attributes in Workflow

You can upsert Search Attributes to add, update, or remove Search Attributes from within Workflow code using the UpsertTypedSearchAttributes() method with a set of updates.

.NET SDK Workflow upsert Search Attributes example

```csharp // These only need to be created once, so it is common to make them static readonly even though we // create inline here for demonstration var myKeywordAttributeKey = SearchAttributeKey.CreateKeyword("MyKeywordAttribute"); var myTextAttributeKey = SearchAttributeKey.CreateText("MyTextAttribute"); // Add/Update the keyword one and remove the text one Workflow.UpsertTypedSearchAttributes( myKeywordAttributeKey.ValueSet("SomeKeywordValue"), myTextAttributeKey.ValueUnset()); ``` This example shows how to upsert Search Attributes from within Workflow code, including updating and removing attributes.

.NET SDK list Workflow Executions with filter

Use the ListWorkflowsAsync() method on the Client and pass a List Filter as an argument to filter the listed Workflows. The result is an async enumerable.

.NET SDK list Workflow Executions example

```csharp await foreach (var wf in client.ListWorkflowsAsync("WorkflowType='GreetingWorkflow'")) { Console.WriteLine("Workflow: {0}", wf.Id); } ``` This example shows how to list Workflow Executions using a List Filter.

Read Search Attributes on Client in .NET SDK

On the Client, you can read the value of a Search Attribute by calling Describe on a WorkflowHandle.

Read Search Attributes in Workflow in .NET SDK

In the Workflow, you can read the value of a Search Attribute by looking at WorkflowInfo.

Give your agent this brain