# 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](/workflow-builder/ion-webhooks-component.md) 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`

<figure><img src="/files/bBQ7BrZ76A6g5tlVZlSs" 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="/files/K4Bpq9F12UqJjh5gsn0P" alt=""><figcaption></figcaption></figure>

Configure the Connection, GraphQL Query, and GraphQL Variables

<figure><img src="/files/QUoYMzNWlecHnJJXXrha" alt=""><figcaption></figcaption></figure>

Use the following query:

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

Use the following query variables:

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

Add a reference in the query variable to the incoming id from the webhook trigger

<figure><img src="/files/Q1ciApqvFd9Gp3YairOl" alt=""><figcaption></figcaption></figure>

Refer to [this](/workflow-builder/first-resonance-ion-component/using-the-first-resonance-ion-component.md) 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`

<figure><img src="/files/dt0h2qMac7dWq4UCJ08V" alt=""><figcaption></figcaption></figure>

Configure the branch step to check the Tracking Level:

<figure><img src="/files/B6MHBqq8AcwLjXz71JMO" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/Be59pDZKdPIqLaAztIOn" alt=""><figcaption></figcaption></figure>

Select `does not exist` for the Operator

<figure><img src="/files/lBJNe2RPJSI9lDgXbRyq" 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="/files/VDoEyppCkaNuT9R9JdAZ" alt=""><figcaption></figcaption></figure>

Enter `trackingStrategy` for the Key and `N/A` for the Value

<figure><img src="/files/GCeSLRlLQXsiyIgXbs4C" 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="/files/ZfLYn9y19u9XhP2Gcxu4" alt=""><figcaption></figcaption></figure>

Enter `trackingStrategy` for the Key

Enter references to the `trackingType` and `sourcingStrategy` for the Value separated by a -

<figure><img src="/files/4bHWiaRYlybR5X4Zc8E2" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/uPTaMsfpVF1N99jpOSqO" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/x3tjZk5n5PvWaj1iLpkn" 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="/files/fdvd1ZRPVDTuGVNl5G6o" alt=""><figcaption></figcaption></figure>

Enter in `trackingStrategy` for the Key

<figure><img src="/files/COvDzdRyls2DVTgTEDHo" 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="/files/l4u3IY1U38Jr01bl07Qi" alt=""><figcaption></figcaption></figure>

Configure the Connection, GraphQL Query, and GraphQL Variables

<figure><img src="/files/QUoYMzNWlecHnJJXXrha" alt=""><figcaption></figcaption></figure>

Use the following query:

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

Use the following query variables:

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

Add a references in the query variable to the partId, etag, and value.

Reference to the partId:

<figure><img src="/files/dimee8xLzNQz5SrZEjhu" alt=""><figcaption></figcaption></figure>

Reference to the etag:

<figure><img src="/files/remjwSS3m50re91Slcyx" alt=""><figcaption></figcaption></figure>

Reference to the value:

<figure><img src="/files/caeMBWFrEtvz6VhaXyQr" alt=""><figcaption></figcaption></figure>

The query variables should look like this:

<figure><img src="/files/S9PCZXIgOVIrPeqQ9ljf" alt=""><figcaption></figcaption></figure>

The final flow should resemble this:

<figure><img src="/files/Z0NQ5sQMAsNebrQqpyJs" alt=""><figcaption></figcaption></figure>
