# WorkCOM Inspection Assignment Workflow

Workplace inspections created through the WorkCOM module automatically assign an inspector when one is not provided. The workflow uses the `inspection_assignment_rules` table to pick an appropriate user based on the inspection district.

Managers can adjust these rules by opening the **WorkCOM Inspection Assignment Rules** modal and editing the table. Each rule now lists a `district_id` and the `inspector_id` to apply along with optional `email` and `phone` contacts. The `send_email` and `send_sms` flags determine whether notifications are sent to those addresses. The first rule that matches the new inspection is used.

When an inspection record is inserted the workflow performs these steps:

1. **query_records** – loads `inspection_assignment_rules` filtered by the inspection's `district_id`.
2. **map_fields** – copies the first rule's `inspector_id` into a workflow context variable.
3. **save_record** – updates `workplace_inspections.inspector_id` with that value if it was not supplied in the original request.

Adjusting the rules allows each facility to control which investigators receive new inspections without modifying any code.

Other assignment-rule modules, including the original *Inspection Assignment Rules* and *OHS Assignment Rules* configurations, continue to rely on their previous field sets. Only the WorkCOM workflow uses the `district_id`, `email`, `phone`, `send_email`, and `send_sms` fields.

## Add Assignment Button

Inspectors can also be assigned manually from the **WorkCOM Inspection Assignment** modal. This interface now includes an **Add Assignment** button that loads pending inspections from the `inspection_requests` table. Selecting a request from the dropdown populates the assignment form with details from that record.

Assignments created through the modal are stored in the **WorkCOM Inspection Assignment** table. Newly created rows appear immediately in the table so managers can track which inspections have been scheduled.
