> For the complete documentation index, see [llms.txt](https://docs.pyck.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pyck.cloud/graphql-api/mutations/setassignee.md).

# Set Assignee

setAssignee Mutation

Audience: Programmer

Updates or sets the assignee for a running workflow instance using Temporal's synchronous workflow update mechanism.

## Arguments

| Name    | Type                | Description                                  |
| ------- | ------------------- | -------------------------------------------- |
| `input` | `SetAssigneeInput!` | Input data for setting the workflow assignee |

## Return Type

`SetAssigneeResponse` - Contains the updated assignee information for the workflow.

## Input Fields

`SetAssigneeInput`:

| Field        | Type      | Description                                                       |
| ------------ | --------- | ----------------------------------------------------------------- |
| `id`         | `String!` | The unique identifier of the workflow instance                    |
| `runID`      | `String!` | The run ID of the workflow instance                               |
| `assigneeID` | `ID`      | Optional user ID to assign. If null, defaults to the current user |

## Return Fields

`SetAssigneeResponse`:

| Field      | Type      | Description                                  |
| ---------- | --------- | -------------------------------------------- |
| `assignee` | `String!` | The ID of the assigned user after the update |

## Usage Example

### Setting a specific assignee

```graphql
mutation {
  setAssignee(
    input: {
      id: "order-fulfillment-wf-12345",
      runID: "abc123de-f456-7890-ghij-klmnopqrstuv",
      assigneeID: "user_987654"
    }
  ) {
    assignee
  }
}
```

### Setting the current user as assignee

```graphql
mutation {
  setAssignee(
    input: {
      id: "inventory-check-wf-67890",
      runID: "xyz987fe-d321-6543-mnop-qrstuvwxyzab"
      # assigneeID is omitted, defaults to current user
    }
  ) {
    assignee
  }
}
```

## JavaScript Example

```javascript
const SET_ASSIGNEE = gql`
  mutation SetAssignee($input: SetAssigneeInput!) {
    setAssignee(input: $input) {
      assignee
    }
  }
`;

// Example 1: Assign a specific user
const { data: specificUser } = await client.mutate({
  mutation: SET_ASSIGNEE,
  variables: {
    input: {
      id: "order-fulfillment-wf-12345",
      runID: "abc123de-f456-7890-ghij-klmnopqrstuv",
      assigneeID: "user_987654"
    }
  }
});

console.log(`Workflow assigned to: ${specificUser.setAssignee.assignee}`);

// Example 2: Assign to current user (omit assigneeID)
const { data: currentUser } = await client.mutate({
  mutation: SET_ASSIGNEE,
  variables: {
    input: {
      id: "inventory-check-wf-67890",
      runID: "xyz987fe-d321-6543-mnop-qrstuvwxyzab"
    }
  }
});

console.log(`Workflow assigned to current user: ${currentUser.setAssignee.assignee}`);
```

## Error Handling

The mutation will return an error in the following cases:

* **Invalid ID**: When the `id` field is empty or missing
* **Invalid RunID**: When the `runID` field is empty or missing
* **Invalid workflowClient**: When the workflow client cannot be obtained for the tenant
* **Update failure**: When the Temporal workflow update operation fails

### Error Response Example

```javascript
try {
  const { data } = await client.mutate({
    mutation: SET_ASSIGNEE,
    variables: {
      input: {
        id: "", // Empty workflow ID will cause error
        runID: "xyz987fe-d321-6543-mnop-qrstuvwxyzab"
      }
    }
  });
} catch (error) {
  console.error("Failed to set assignee:", error.message);
  // Output: "invalid WorkflowID"
}
```

## Important Notes

* This mutation uses Temporal's synchronous workflow update mechanism (`UpdateWorkflow`)
* The update is applied immediately to the running workflow instance
* When `assigneeID` is not provided (null), the mutation automatically assigns the workflow to the current authenticated user
* Both `id` and `runID` are required to uniquely identify the workflow instance
* The workflow must be running and accessible in the Temporal cluster for the update to succeed
* This operation updates the workflow's internal state and may trigger workflow logic based on assignee changes
* The returned `assignee` field contains the user ID string after the update is applied
* To clear an assignee, you would need to pass an empty string as `assigneeID` (though the current implementation defaults to current user when null)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pyck.cloud/graphql-api/mutations/setassignee.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
