# Higher priority jobs

### Using the priority export databox

How to use the priority export databox to read the service priority and display a message,

{% embed url="<https://youtu.be/IIHsrVQZFzY>" %}

The following example demonstrates how a **Startup script** uses a SQL Databox to check for previous jobs raised within the past 5 minutes by the same user, on the same property and writes the details into a script Databox.

Later, a **Custom Script** checks the details of any previous job found.

### The Startup Script

This is the Startup Script which executes Databox Read i.e. **Keyfax.MultiOrderCheck** where the results are written to the Databox **MultipleJobs.Details:**&#x20;

<div align="center"><figure><img src="https://2882349412-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MARm6St_qFGM52R3pBa%2Fuploads%2FJlCkCnzHpm3imI32fQav%2F2023-05-09_11h51_43.png?alt=media&#x26;token=41be1ea4-8cfc-493f-901a-175c04d4132d" alt=""><figcaption><p>The Startup Script</p></figcaption></figure></div>

### The SQL Databox

This query will looks for any orders submitted in the last 5 minutes, for the same operator and Asset ID. The query runs against the Keyfax table **syOrder**:&#x20;

<div align="center"><figure><img src="https://2882349412-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MARm6St_qFGM52R3pBa%2Fuploads%2FEF6lgHDMuW9Z90slNP3b%2F2023-05-09_12h14_02.png?alt=media&#x26;token=b3bdaca5-a841-4fef-88b4-7997dc2239fa" alt=""><figcaption><p>MultiOrderCheck SQL Databox</p></figcaption></figure></div>

In the WHERE clause, you'll see references to other Databoxes in **{**&#x63;url&#x79;**}** braces, including **Keyfax.DateChecks** below (subtracting 5 minutes from the current time could easily have been done using SQL in the above query but it is split out into a Databox just for demonstration purposes):

<div align="center"><figure><img src="https://2882349412-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MARm6St_qFGM52R3pBa%2Fuploads%2F1fJhCPQmxZ5kBh6qQHIw%2F2023-05-09_12h29_53.png?alt=media&#x26;token=7f8f28e5-1232-47b2-9821-aa2ee27168f3" alt=""><figcaption><p>A Databox that subtracts 5 minutes from the current time</p></figcaption></figure></div>

### Using the results of the above Query

The Databox **MultipleJobs.Details** contains a number of Expressions, two of which are Conditional and are checking for values representing the Priority (you will see their use in the **Result script** below).&#x20;

<div align="center"><figure><img src="https://2882349412-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MARm6St_qFGM52R3pBa%2Fuploads%2F9BpsiT69Tg0X27NTRqoE%2F2023-05-09_12h21_37.png?alt=media&#x26;token=dd9e14d2-62fb-4ef2-9214-25480f13a37d" alt=""><figcaption><p>MultipleJobs.Details' Expressions</p></figcaption></figure></div>

### The Custom Script

If a job is found and it has an **Urgent** priority then the priority of the current job is checked. If the current job is an **Urgent** or **Emergency** priority then nothing is done. If the current job is a **Routine**, the priority needs to increase to an **Urgent** to match the previous job.

If there is a job found and it has an **Emergency** priority then the priority of the current job is checked. If the current job is an **Emergency** then nothing is done. If the current job is anything else, the priority needs to increase to an **Emergency** to match the previous job.

To add another level of checking, as notification to the Operator, a question is displayed informing the Operator that a priority change is required. If they continue, the priority will be upgraded accordingly.

<div align="left"><figure><img src="https://2882349412-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MARm6St_qFGM52R3pBa%2Fuploads%2FqT6HVhZD5zjErnVwU7rM%2F2023-05-09_12h37_53.png?alt=media&#x26;token=c0acb1d3-4c31-4fa4-bd89-7cf67ec7993f" alt=""><figcaption><p>The Priority checking custom script</p></figcaption></figure></div>
