# CreateIncidentResponse Fields

## Copy Field Maps

{% hint style="info" %}
It is worth copying all relevant OOTB Field Maps as are necessary for your integration before using any of them in your Field Records - thereby mitigating the risk of any potential issues with future upgrades.
{% endhint %}

The Field Map we shall use for our CreateIncidentResponse Field record is:

* Source Reference

To copy the Source Reference Field Map, navigate to the **'Field Maps' icon**.

![](https://796541950-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MQmgaddAbbZQNDQsJoT%2F-MQpt1GLn3DWYoU7tPfr%2FV2%20-%20Fields%20-%20CreateIncidentResponse%201.png?alt=media\&token=70b6855f-cdef-4a81-879c-094818f8b560)

1\) Click on the **ellipsis** to the right of the **Source Reference** Field Map & click **Copy**.

## Copy Field Map Modal

The fields to edit for the Copy Field Map modal are as follows:

|  #  | Field  | Description                                                                                          | Value        |
| :-: | ------ | ---------------------------------------------------------------------------------------------------- | ------------ |
|  2  | Name\* | The name of your field map. (If left unedited, it will append the word 'Copy' to the existing name.) | \<Your Name> |

{% hint style="success" %}
*\*Name: We have chosen to prefix the existing Field Map Name with the initials of our Integration (you are free to choose any appropriate means of identifying/differentiating your copy).*
{% endhint %}

*Your Copy Field Map modal should look like this:*

![](https://796541950-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MQmgaddAbbZQNDQsJoT%2F-MQptQ7Qlf401RxtMZ3C%2FV2%20-%20Fields%20-%20CreateIncidentResponse%202.png?alt=media\&token=2ffc0216-3d01-4ead-83fc-50cf4dc091a5)

{% hint style="info" %}
Integration should be automatically populated.
{% endhint %}

3\) Click **Copy**.

You will be redirected to the Details page of the newly created Field Map.

## Field: result.sys\_id

In **Unifi Integration Designer**, from the **CreateIncidentResponse** page, navigate to **Message > Fields**. Click **New**.

The fields to be configured for the sys\_id New Field modal are as follows:

| #   | Field             | Description                                                                             | Value                                                           |
| --- | ----------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| \*  | Message           | The Message this Field record is linked with.                                           | 'CreateIncidentResponse'                                        |
| 4   | Description       | Describe what this field is for and any specific details that might help you in future. | 'Extract returned sys\_id & store in stage.external\_reference' |
| \*  | Active            | Set to true to use this Field record for processing.                                    | \<true>                                                         |
| 5   | Field map         | The Field Map this Field record is linked with.                                         | 'IS - Source Reference'\*\*                                     |
| 6\* | Map to field      | Use this Field record to represent a field on a source/target table.                    | \<false>                                                        |
| 7   | Path              | Where in the payload the data will be placed.                                           | 'result'                                                        |
| 8   | Propert&#x79;*\** | The property in the payload the data will be written to.                                | 'sys\_id'                                                       |
| \*  | Inbound           | Set to true to use for inbound Messages.                                                | \<true>                                                         |
| 9\* | Outbound          | Set to true to use for outbound Messages.                                               | \<false>                                                        |

*\*These fields are automatically defaulted to true, or automatically populated.*

*\*\*Field map: Value may vary. Choose the copy Field Map you created for your Integration.*

{% hint style="info" %}
*\*Property: We are setting 'sys\_id' as the property because that is what is required by the table API. If it were possible, it would better to use something more meaningful, like the Number of the ticket integrated with, as this aids in debugging.*
{% endhint %}

*The 'result.sys\_id' New Field modal should look like this:*

![](https://796541950-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MQmgaddAbbZQNDQsJoT%2F-MQpuihL2wrNdGv4KP97%2FV2%20-%20Fields%20-%20CreateIncidentResponse%203.png?alt=media\&token=53415ad6-eaa7-4a30-a62c-79c32bf0aa09)

10\) **Submit** the record.

You will be redirected back to the Fields page of the CreateIncidentResponse Message.

## Build

Now that we’ve configured the Field records for the CreateIncidentResponse message, we are ready to build our message scripts.

*The following Field record should now be in place for your CreateIncidentResponse messsage:*

![](https://796541950-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MQmgaddAbbZQNDQsJoT%2F-MQpv4CEfgMNuxYLkFjw%2FV2%20-%20Fields%20-%20CreateIncidentResponse%204.png?alt=media\&token=933fbf6b-8956-42cc-ad31-b4abd81af8d7)

{% hint style="success" %}
**Feature Alert**: In the picture above you will notice that a 'Build Integration' button has appeared in the banner at the top of the page. Whenever a change is made to a Field record that is associated to a Message *(whether that is being created, updated, or deleted)* the button will be available and acts as a visual reminder that changes have been made and Message Script(s) need to be built. We will talk more about this feature in the [Build Integration Level](https://docs.sharelogic.com/unifi/2.2/integration-guides/outbound-incident-guide/build-integration-level) page.
{% endhint %}

11\) Click on **Build Message**.

You will see the 'Message build successful' Info Message.

![](https://796541950-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MQmgaddAbbZQNDQsJoT%2F-MQpw-UkRT4yNI8OFi1s%2FV2%20-%20Fields%20-%20CreateIncidentResponse%205.png?alt=media\&token=731313b7-1700-4776-b086-9de59807715b)

12\) Navigate to **Advanced > Script Editor** to view the auto-generated code.

*Your Script Editor fields should look like this:*

![](https://796541950-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MRuU4ShEsNue3MupIGg%2F-MRuXUT0yGYROS1mjxOG%2FV2%20-%20Fields%20-%20CreateIncidentResponse%206.png?alt=media\&token=27b93ba4-8540-48de-a196-2f8afef04d2a)

## Message Scripts

{% hint style="info" %}
The newly auto-generated code will appear between a Begin & End Comment immediately prior to any code that was already there.
{% endhint %}

```javascript
//===== [ws] Begin Unifi Auto Generated Code =====//

/*
 * This code (between the Begin and End comments) is generated from the
 * Field and Field mapping records which are configured as part of the integration.
 *
 * All code either above or below the comments will be automatically maintained
 * through the build cycle.
 *
 * WARNING: Do not edit the Begin or End comments.
 */

(New auto-generated code will appear here)

//===== [ws] End Unifi Auto Generated Code =====//

(Old pre-existing code will appear here)
```

We will now examine our new, auto-generated Message Scripts.

*Payload to Stage:*

```javascript
//===== [ws] Begin Unifi Auto Generated Code =====//

/*
 * This code (between the Begin and End comments) is generated from the
 * Field and Field mapping records which are configured as part of the integration.
 *
 * All code either above or below the comments will be automatically maintained
 * through the build cycle.
 *
 * WARNING: Do not edit the Begin or End comments.
 */

x_snd_eb.ws_console.execute("Mapping result.sys_id [x_snd_eb_field.do?sys_id=a7653549dbf9985094dbd7795e9619bc]", function () {
  log.debug("Field map: IS - Source Reference [x_snd_eb_field_map.do?sys_id=c930653cdb7d585094dbd7795e96199a]");
  payload = payload || {};
  payload.result = payload.result || {};
  var $payload = payload.result;

  stage.external_reference = '' + ($payload.sys_id || '');

});

if (x_snd_eb.ws_console.has_error) {
  var errors = x_snd_eb.ws_console.get({type: 'error'});
  if (errors.length) {
    throw errors[0];
  }
}

//===== [ws] End Unifi Auto Generated Code =====//
```

*Stage to Target:*

{% hint style="success" %}
The code we had previously added when configuring our Message as per the '[CreateIncidentResponse Message](https://docs.sharelogic.com/unifi/2.2/integration-guides/outbound-incident-guide/createincidentresponse-message#scripts)' page is still in place.
{% endhint %}

```javascript
bond.setOpen();
```

{% hint style="info" %}
*Both the stage & bond external reference are being set to the sys id only because we are integrating with the table API and that's what it requires. If possible, it is better to use something more meaningful, like the Number of the ticket integrated with, as this aids in debugging.*
{% endhint %}

*Next, we will configure the **CreateIncident** Message.*
