# Auto Set Custom Attribute

## Scenario

Every time a part is created, set the custom attribute `Tracking Strategy` based on the following table:

| Tracking Level | Sourcing Strategy | Tracking Strategy |
| -------------- | ----------------- | ----------------- |
| None           | Make              | N/A               |
| None           | Buy               | N/A               |
| Lot            | Make              | Lot - Make        |
| Lot            | Buy               | Lot - Buy         |
| Serial         | Make              | Serial - Make     |
| Serial         | Buy               | Serial - Buy      |

### Trigger

The flow should be triggered when a part is created.

### Steps

* Create a new flow using the [ion-webhooks](https://manual.firstresonance.io/workflow-builder/ion-webhooks-component) component. Configure the ion-webhooks step by setting the Connection, providing a name for the webhook receiver, and adding an action. In this example we want the flow to be triggered when a part is created so the action will be `Parts - Create`&#x20;

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2Fugs1l74l76hcQaUWORXd%2Fimage.png?alt=media&#x26;token=5b503944-4783-42d0-9677-95a6d18ff789" alt=""><figcaption></figcaption></figure>

* Add a step that uses the `First Resonance ION` component. Click on the `+` icon at the bottom of the flow then search for `First Resonance ION`. Click on `Run GraphQL Query`.

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2F45KC9mueNJCwxjjx9tFD%2Fimage.png?alt=media&#x26;token=f3c69ac6-bd0d-47ba-aff1-46c0325bb1a6" alt=""><figcaption></figcaption></figure>

&#x20;      Configure the Connection, GraphQL Query, and GraphQL Variables

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2F8BzVIVnV2SAiROone458%2Fimage.png?alt=media&#x26;token=772a3d03-65d9-4af6-94d8-e07939e7ebda" alt=""><figcaption></figcaption></figure>

&#x20;      Use the following query:&#x20;

```graphql
query getParts($filters:PartsInputFilters!) {
  parts(filters:$filters) {
    edges {
      node {
        id
        _etag
        partNumber
        sourcingStrategy
        trackingType
      }
    }
  }
}
```

&#x20;     Use the following query variables:

```json
{
  "filters": {
    "id": {
      "eq": 
    }
  }
}
```

&#x20;      Add a reference in the query variable to the incoming id from the webhook trigger

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FEM7jI4OigdKjJPGrOAxt%2Fimage.png?alt=media&#x26;token=89de7e6b-2742-42c7-b323-9056c07b3a6b" alt=""><figcaption></figcaption></figure>

&#x20;      Refer to [this](https://manual.firstresonance.io/workflow-builder/first-resonance-ion-component/using-the-first-resonance-ion-component) for detailed documentation on using the First Resonance ION component.

* Add a step that branches based on the value of the Tracking Level. Search for "branch" and select `If Condition is Met` &#x20;

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FE1faB4yuKq7XJFnTGKmi%2Fimage.png?alt=media&#x26;token=3432161b-4550-4b8a-a30f-1eeb1717ca4c" alt=""><figcaption></figcaption></figure>

&#x20;      Configure the branch step to check the Tracking Level:

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FPflXNSbLvVBRm3zg24tb%2Fimage.png?alt=media&#x26;token=6c7c5ea4-2c85-4a2e-85a0-7b30e9be5e4a" alt=""><figcaption></figcaption></figure>

&#x20;      Click the icon in the first `Field` and configure the input to the output of the previous step.&#x20;

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FhAA4awF6AJD05APBmW2Y%2Fimage.png?alt=media&#x26;token=1e84b9b2-529b-46fa-90fd-0d9cecb3b33b" alt=""><figcaption></figcaption></figure>

&#x20;      Select `does not exist` for the Operator

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FHR84MS9qKfbb6KbxwMCw%2Fimage.png?alt=media&#x26;token=edf8bf07-1aac-4ac0-9fb7-329ca96b8d57" alt=""><figcaption></figcaption></figure>

* Click on the `+` icon in the "Tracking is None" side of the branch. Search for "Execution save value". Select `Execution - Save Value`

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2F0RCLLVUcdQIJKPYBwbRB%2Fimage.png?alt=media&#x26;token=80556dac-7291-4ee5-a2b2-d60c126c8ad0" alt=""><figcaption></figcaption></figure>

&#x20;      Enter `trackingStrategy` for the Key and `N/A` for the Value

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2F2kdA8WdAkdO37PDfKeNR%2Fimage.png?alt=media&#x26;token=66493fcc-7a0f-4d52-b664-b8dbf8ff3415" alt=""><figcaption></figcaption></figure>

* Click on the `+` icon in the "Else" side of the branch. Search for "Execution save value". Select `Execution - Save Value`

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2Fb89oTaEI3RQ5SXBu5hXl%2Fimage.png?alt=media&#x26;token=2865e04b-6e01-45e3-9396-5c9b6f5e959a" alt=""><figcaption></figcaption></figure>

&#x20;     Enter `trackingStrategy` for the Key

&#x20;     Enter references to the `trackingType` and `sourcingStrategy` for the Value separated by a -

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FeG1MgKmSp9WPnZ5u2brU%2Fimage.png?alt=media&#x26;token=f562c5ba-e6d2-4c7d-86ca-b64af0eecee7" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2F4RJXWBjqCQQzi9IIDpxe%2Fimage.png?alt=media&#x26;token=8d1cfcb0-82b2-43a5-a6e8-3d30f54e24ec" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FgAJVuKdsKQkVs3o31M4k%2Fimage.png?alt=media&#x26;token=cd1d6eeb-e7b8-471a-8c5a-b1d1070faefa" alt=""><figcaption></figcaption></figure>

* Add a step at the end of the flow that will return the value of `trackingStrategy`. Click on the `+` icon at the bottom of the flow then search for "Execution get value". Click on `Execution - Get Value`

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FQGnEs75JFgs94VjKTnTr%2Fimage.png?alt=media&#x26;token=430d3c83-41bc-4a72-884c-a02f0b0ea105" alt=""><figcaption></figcaption></figure>

&#x20;      Enter in `trackingStrategy` for the Key&#x20;

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FeUr7SdELfpZSxYIJZDLg%2Fimage.png?alt=media&#x26;token=a50678d4-7516-4436-9118-ca77279806ed" alt=""><figcaption></figcaption></figure>

* Add a step to set a custom attribute to the value of `trackingStrategy`. Click on the `+` icon at the bottom of the flow then search for "First Resonance ION". Click on `Run GraphQL Query`.

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2Fo3um2q3lcxCkMpRJb3Py%2Fimage.png?alt=media&#x26;token=30fd60ab-f05c-4b30-95da-aa0a6e4a2a86" alt=""><figcaption></figcaption></figure>

&#x20;      Configure the Connection, GraphQL Query, and GraphQL Variables

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2F8BzVIVnV2SAiROone458%2Fimage.png?alt=media&#x26;token=772a3d03-65d9-4af6-94d8-e07939e7ebda" alt=""><figcaption></figcaption></figure>

&#x20;      Use the following query:&#x20;

```graphql
mutation UpdatePartAttributes($input: UpdatePartAttributeInput!) {
  updatePartAttribute(input: $input) {
    partAttribute {
			partId
      Etag
      key
      value
    }
  }
}
```

&#x20;     Use the following query variables:

```json
{
  "input": {
    "partId": ,
    "key": "",
    "value": "",
    "etag": ""
  }
}
```

&#x20;      Add a references in the query variable to the partId, etag, and value.

&#x20;      Reference to the partId:&#x20;

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2Fqbz2BKCUg8pDXJUg1037%2Fimage.png?alt=media&#x26;token=84af8cc2-1f28-49d4-99d3-9ecc6a44ac1c" alt=""><figcaption></figcaption></figure>

&#x20;      Reference to the etag:&#x20;

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FB7B8Cl5QWE3GZvUfE8Ae%2Fimage.png?alt=media&#x26;token=b60784ec-09fc-4668-a9e9-c9d38dbc3140" alt=""><figcaption></figcaption></figure>

&#x20;      Reference to the value:&#x20;

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FSIlUFG01D9ZvbhaHd1id%2Fimage.png?alt=media&#x26;token=58a6d3f1-482b-451b-92db-4cb1bcf43259" alt=""><figcaption></figcaption></figure>

&#x20;      The query variables should look like this:&#x20;

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FE4ZUpVz2nyhPDNZHONiH%2Fimage.png?alt=media&#x26;token=8c05f568-7255-4f81-9a7b-d993862da995" alt=""><figcaption></figcaption></figure>

&#x20;      Refer to [this](https://manual.firstresonance.io/workflow-builder/first-resonance-ion-component/using-the-first-resonance-ion-component) for detailed documentation on using the First Resonance ION component.

The final flow should resemble this:&#x20;

<figure><img src="https://3615148728-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LkRqYp6lJhwxjYdzYG8%2Fuploads%2FgNPwkyGKB10zb4eg9u9i%2Fimage.png?alt=media&#x26;token=fce97691-27be-45fe-8a14-cfd540710065" alt=""><figcaption></figcaption></figure>
