> For the complete documentation index, see [llms.txt](https://manual.firstresonance.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.firstresonance.io/features/ion-actions/ion-actions-examples-for-supply-chain.md).

# ION Actions examples for Supply Chain

## Required fields before approval

Mandate that specific PO line attributes are populated before submitting for approval

```
{
  "enabled": true,
  "title": "Purchase line items must have a need date",
  "target": "PURCHASEORDERLINE",
  "eventType": "UPDATE",
  "ruleType": "VALIDATION",
  "errorState": "ALLOW",
  "context": "{ purchaseOrderLine(id: $id) { id needDate } }",
  "code": "if context.get('changes', {}).get('purchaseOrderLines', {}).get('status', {}).get('new') == 'requested' and context.get('purchaseOrderLine', {}).get('needDate') is None: raise ValidationError()"
}
```

Mandate that specific PO header (custom) attributes are populated before submitting for approval

```
{
            "enabled": true,
            "title": "Purchase requires a justification before it can be ordered"
            "target": "PURCHASEORDERLINE",
            "eventType": "UPDATE",
            "errorState": "ALLOW",
            "context": "{ purchaseOrderLine(id: $id) { purchaseOrder {id attributes {key value}}  } }",
            "code": "if context.get('changes', {}).get('purchaseOrderLines', {}).get('status', {}).get('new') == 'requested' and any(attribute.get('key') == 'PO Justification' and not attribute.get('value') for attribute in context['purchaseOrderLine'].get('purchaseOrder', {}).get('attributes', [])): raise ValidationError()"      
 }
```

## Purchase Approvals

We used to rely on ION Actions to enforce purchase order approval levels, but we now have a first class method to do so that is easily understandable and maintained. Check that out [here.](/features/purchasing/purchase-orders/purchase-order-approvals.md)

### Other Example Rules:

### Receipt line items must have a location

```
{
  "create_rule": {
    "title": "Receipt line items must have a location",
    "ruleType": "VALIDATION",
    "eventType": "CREATE",
    "target": "RECEIPTITEM",
    "code": "if context.get('receiptItem', {}).get('partInventory', {}).get('locationId') is None: raise ValidationError()",
    "context": "{ receiptItem(id: $id) { id partInventory{locationId} } }",
    "enabled": true
    }
}
    
```

### Required fields for part creation

```
{
    "create_rule": {
    "title": "Required fields for part creation",
    "ruleType": "VALIDATION",
    "eventType": "CREATE",
    "target": "PART",
    "code": "if (context.get('part', {}).get('partType') == 'PART') and any([not context.get('part', {}).get('revision') == '', not context.get('part', {}).get('description') == '', not context.get('part', {}).get('trackingType') == '', not context.get('part', {}).get('sourcingStrategy') == '', not context.get('part', {}).get('unitOfMeasure') == '']): raise ValidationError()",
    "context": "{ part(id: $id) { id revision revisionScheme description trackingType sourcingStrategy partType unitOfMeasure { id } attributes { key value } } }",
    "enabled": false
    }
}
```


---

# 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://manual.firstresonance.io/features/ion-actions/ion-actions-examples-for-supply-chain.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.
