# ION Actions examples for Runs and Procedures

#### All Steps Need Dependencies:

```json
{
  "create_rule": {
    "enabled": true,
    "title": "Check if Step has dependencies",
    "target": "PROCEDURE",
    "eventType": "UPDATE",
    "ruleType": "VALIDATION",
    "errorState": "ALLOW",
    "context": "{ procedure(id: $id) { id steps{location{name} upstreamStepIds downstreamStepIds } } }",
    "code": "if (context.get('changes', {}).get('procedures', {}).get('status', {}).get('new') == 'in_review' and any([step for step in context.get('procedure', {}).get('steps', []) if not (step.get('upstreamStepIds') or step.get('downstreamStepIds'))])): raise ValidationError()"
  }
}
```

#### All Child Steps Need Dependencies:

```json
{
  "create_rule": {
    "enabled": true,
    "title": "Check if Child Step has dependencies",
    "target": "PROCEDURE",
    "eventType": "UPDATE",
    "ruleType": "VALIDATION",
    "errorState": "ALLOW",
    "context": "{ procedure (id: $id) { id steps { location { id } title isStandardStep steps { title isStandardStep downstreamStepIds upstreamStepIds location { name } } } } }",
    "code": "if context.get('changes', {}).get('procedures', {}).get('status', {}).get('new') == 'in_review' and any([step for step in context.get('procedure', {}).get('steps', []) if 'steps' in step and len(step.get('steps', [])) > 1 and any([nested_step for nested_step in step.get('steps', []) if not nested_step.get('upstreamStepIds') and not nested_step.get('downstreamStepIds')])]): raise ValidationError()"
  }
}
```

#### All Steps Need a Location

```json
{
  "create_rule": {
    "enabled": true,
    "title": "Check if Step has Location",
    "target": "PROCEDURE",
    "eventType": "UPDATE",
    "ruleType": "VALIDATION",
    "errorState": "ALLOW",
    "context": "{ procedure (id: $id) { id steps { location {name} title standardStepStatus steps { title standardStepStatus downstreamStepIds upstreamStepIds } } } }",
    "code": "if context.get('changes', {}).get('procedures', {}).get('status', {}).get('new') == 'in_review' and [step for step in context.get('procedure', {}).get('steps', []) if step.get('location') is None and step.get('standardStepStatus') is None]: raise ValidationError()"
  }
}
```

#### All Child Steps Need a Location

```json
{
  "create_rule": {
    "enabled": true,
    "title": "Check if Child Step has Location",
    "target": "PROCEDURE",
    "eventType": "UPDATE",
    "ruleType": "VALIDATION",
    "errorState": "ALLOW",
    "context": "{ procedure (id: $id) { id steps { location { id } title standardStepStatus steps { title standardStepStatus downstreamStepIds upstreamStepIds location { name } } } } }",
    "code": "if context.get('changes', {}).get('procedures', {}).get('status', {}).get('new') == 'in_review' and any(nested_step for step in context.get('procedure', {}).get('steps', []) for nested_step in step.get('steps', []) if nested_step.get('standardStepStatus') is None and nested_step.get('location') is None): raise ValidationError()"
  }
}
```

#### A Procedure can only move to ‘In Review’ when the correct reviewers from the correct teams have been added:

```json
{
  "create_rule": {
    "enabled": true,
    "title": "Procedure requires the correct teams to review",
    "target": "PROCEDURE",
    "eventType": "UPDATE",
    "ruleType": "VALIDATION",
    "errorState": "ALLOW",
    "context": "{ procedure (id: $id) { type attributes {key value} reviewRequests { id status reviewer { id teams { name } roles { name } } } } }",
    "code": "if context.get('changes', {}).get('procedures', {}).get('status', {}).get('new') == 'in_review' and [attributes for attributes in context.get('procedure',{}).get('attribute', {}) if context.get('attribute', {}).get('key') == 'Procedure Type' and context.get('attribute', {}).get('value') == 'Build'] and not (any('Responsible Engineer' in team.get('name', '') for reviewer in context.get('procedure', {}).get('reviewRequests', []) for team in reviewer.get('reviewer', {}).get('teams', [{}])) and any('Production' in team.get('name', '') for reviewer in context.get('procedure', {}).get('reviewRequests', []) for team in reviewer.get('reviewer', {}).get('teams', [{}])) and any('Mission Assurance' in team.get('name', '') for reviewer in context.get('procedure', {}).get('reviewRequests', []) for team in reviewer.get('reviewer', {}).get('teams', [{}]))): raise ValidationError()"
  }
}
```

#### Check if the custom attribute ‘Procedure Type’ is filled out

```json
{
  "create_rule": {
    "enabled": true,
    "title": "Procedure Type must be filled out",
    "target": "PROCEDURE",
    "eventType": "UPDATE",
    "ruleType": "VALIDATION",
    "errorState": "ALLOW",
    "context": "{ procedure(id: $id) { status, attributes { key, value } } }",
    "code": "if context.get('changes', {}).get('procedures', {}).get('status', {}).get('new') == 'in_review' and any(attributes for attributes in context.get('procedure',{}).get('attributes', {}) if attributes.get('key') == 'Procedure Type' and attributes.get('value') is None): raise ValidationError()"
  }
}
```


---

# 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-runs-and-procedures.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.
