# 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.firstresonance.io/features/ion-actions/ion-actions-examples-for-supply-chain.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
