# Edit CreateIncident Message

## CreateIncident Message

{% hint style="info" %}
Now that we've configured the remote system's Incident form to display our bonded ticket number as the correlation id, we need to update our CreateIncident Message to send it.
{% endhint %}

To ensure that our CreateIncident Message is sending the relevant data we need to configure a new Field record that will send the Incident number as the correlation id. We will make use of the previously copied String Field Map record.

## Field: incident.number

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

The fields to be configured for our incident.number New Field modal are as follows:

| Field          | Description                                                          | Value                                            |
| -------------- | -------------------------------------------------------------------- | ------------------------------------------------ |
| Message\*      | The Message this Field record is linked with.                        | 'CreateIncident'                                 |
| Description    | The description of this Field record.                                | 'The incident number sent as the correlation id' |
| Active\*       | Set to true to use this Field record for processing.                 | \<true>                                          |
| Field map      | The Field Map this Field record is linked with.                      | 'PI - String'\*\*                                |
| Map to field\* | Use this Field record to represent a field on a source/target table. | \<true>                                          |
| Table\*        | The primary source/target table that this Field record is mapped to. | 'Incident' \[incident]                           |
| Element        | The field on the source/target table this Field record is mapped to. | 'Number'                                         |
| Property\*     | The property in the payload the data will be written to.             | 'correlation\_id'                                |
| Inbound\*      | Set to true to use for inbound Messages.                             | \<false>                                         |
| Outbound\*     | Set to true to use for outbound Messages.                            | \<true>                                          |

*\*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.*

*Your 'incident.number' New Field modal should look like this:*

![](https://2763208740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZR0dkdEH0Mm7amiIzsdG%2Fuploads%2FC8dfasjY75zYRqcwYhS4%2Fiupg-edit-createincident-message-1.png?alt=media)

**Submit** the record.

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

## Field: incident.description

{% hint style="info" %}
It is not necessary to configure this Field record to facilitate identifying and returning data from bonded records. It is only included here to facilitate the sending of data in the Description field of the Incident when testing our Integration. You may choose to ignore this if you wish. Similarly, if you had already configured the incident.description Field record for the CreateIncident Message (when completing the 'Outbound incident' Guide), you can ignore this.
{% endhint %}

The ‘incident.description’ (Integration level) Field record should already be in place *(i.e. with Active set to false)*. *This was automatically created by Unifi when we created the Message level record when configuring the Fields for the UpdateIncidentInbound Message*. We will now create its Message level counterpart for the CreateIncident Message.

From the **CreateIncident** Message, navigate to **Message > Fields**.

*Your CreateIncident Fields page should look like this:*

![](https://2763208740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZR0dkdEH0Mm7amiIzsdG%2Fuploads%2FGVZaEdA7qTSIa1A4PLZc%2Fiupg-edit-createincident-message-2.png?alt=media)

Find the **incident.description** (Integration level) Field & set **Active** to **true**.

{% hint style="success" %}
The empty circle icon next to the Field name turns green & contains a green ‘check’ *(to indicate that Message level configuration exists for this Field)* when we set Active to true. *(The ‘Build Integration’ button became visible in the banner when we created the 'incident.number' Field record.)*
{% endhint %}

By setting the Active flag to true on the Integration level Field record listed on the Message, Unifi has automatically created the Message level counterpart.

Click to **open** the **incident.description** (Message level) Field to make a few minor changes.

The incident.description Field record opens to the Details page.

To edit, set **Inherit** to **False**.

![](https://2763208740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZR0dkdEH0Mm7amiIzsdG%2Fuploads%2FAryROkSPcM0ZdOvaI6Ri%2Fiupg-edit-createincident-message-3.png?alt=media)

**Save** the record *(the fields now become editable)*.

Navigate to **Field > Settings**.

Edit the incident.description Field record as follows:

| Field    | Description                                   | Value    |
| -------- | --------------------------------------------- | -------- |
| Path     | Where in the payload the data will be placed. | \[Blank] |
| Inbound  | Set to true to use for inbound Messages.      | \<false> |
| Outbound | Set to true to use for outbound Messages.     | \<true>  |

*Your 'incident.description' Field record should look like this:*

![](https://2763208740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZR0dkdEH0Mm7amiIzsdG%2Fuploads%2FjPbgejoGPX78li0FzYEe%2Fiupg-edit-createincident-message-4.png?alt=media)

**Save** the record.

## Build

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

To quickly navigate to the **CreateIncident** Message from the Details page of the newly created incident.description Field record...

![](https://2763208740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZR0dkdEH0Mm7amiIzsdG%2Fuploads%2F2uVJi2k4caxuJCjBTGI3%2Fv2-edit-createincident-4.png?alt=media)

...click the **'Preview' icon** to the left of the Message field.

*The following Field records should now be in place for your CreateIncident Message:*

![](https://2763208740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZR0dkdEH0Mm7amiIzsdG%2Fuploads%2FJyLEUpaPxpDbePmihTYk%2Fiupg-edit-createincident-message-5.png?alt=media)

Click on **Build Message**.

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

![](https://2763208740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZR0dkdEH0Mm7amiIzsdG%2Fuploads%2FB2gPFxtTuBu1wVk26ZFv%2Fv2-edit-createincident-6.png?alt=media)

Navigate to **Advanced > Script Editor > View > Outbound** to view the auto-generated code.

*Your Script Editor fields should look like this:*

![](https://2763208740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZR0dkdEH0Mm7amiIzsdG%2Fuploads%2FHBHhAZdGxfGUEIk1cUiY%2Fiupg-edit-createincident-message-6.png?alt=media)

## Message Scripts

{% hint style="info" %}
The new auto-generated code *(mapping the incident number to the correlation id & mapping the Incident description)* will appear between the Begin & End Comment along with the code that was already there *(which we had previously created using the Outbound Incident Guide)*. Your code may differ, depending on which Field records you created to satisfy your mapping requirements.
{% endhint %}

***Source 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.checkpoint("MessageScript")

x_snd_eb.ws_console.execute("Mapping incident.number [x_snd_eb_field.do?sys_id=997a766c1be1bc1090dfdb9ebd4bcbb7]", function () {
  log.debug("Field map: PI - String [x_snd_eb_field_map.do?sys_id=da997f7a1b51b81090dfdb9ebd4bcb5e]");
  
  var default_value = (function () {
    return '';
  })();
  
  // Determines whether this instance of the field map is for a mandatory field
  var is_mandatory = false;
  
  if (is_mandatory) {
    $stage.number = '' + (source.number || default_value);
  } else if (source.number != '') {
    $stage.number = '' + source.number;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.caller_id [x_snd_eb_field.do?sys_id=3a5cbbbe1b51b81090dfdb9ebd4bcb66]", function () {
  log.debug("Field map: PI - String [x_snd_eb_field_map.do?sys_id=da997f7a1b51b81090dfdb9ebd4bcb5e]");
  
  var default_value = (function () {
    return '';
  })();
  
  // Determines whether this instance of the field map is for a mandatory field
  var is_mandatory = false;
  
  if (is_mandatory) {
    $stage.caller_id = '' + (source.caller_id || default_value);
  } else if (source.caller_id != '') {
    $stage.caller_id = '' + source.caller_id;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.short_description [x_snd_eb_field.do?sys_id=49debf3e1b51b81090dfdb9ebd4bcba5]", function () {
  log.debug("Field map: PI - String [x_snd_eb_field_map.do?sys_id=da997f7a1b51b81090dfdb9ebd4bcb5e]");
  
  var default_value = (function () {
    return '';
  })();
  
  // Determines whether this instance of the field map is for a mandatory field
  var is_mandatory = false;
  
  if (is_mandatory) {
    $stage.short_description = '' + (source.short_description || default_value);
  } else if (source.short_description != '') {
    $stage.short_description = '' + source.short_description;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.description [x_snd_eb_field.do?sys_id=618a766c1be1bc1090dfdb9ebd4bcb91]", function () {
  log.debug("Field map: PI - String [x_snd_eb_field_map.do?sys_id=da997f7a1b51b81090dfdb9ebd4bcb5e]");
  
  var default_value = (function () {
    return '';
  })();
  
  // Determines whether this instance of the field map is for a mandatory field
  var is_mandatory = false;
  
  if (is_mandatory) {
    $stage.description = '' + (source.description || default_value);
  } else if (source.description != '') {
    $stage.description = '' + source.description;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.state [x_snd_eb_field.do?sys_id=f32e8cc31b91b81090dfdb9ebd4bcb09]", function () {
  log.debug("Field map: PI - Choice [x_snd_eb_field_map.do?sys_id=c7b97f7a1b51b81090dfdb9ebd4bcb62]");
  
  var default_value = (function () {
    return '';
  })();
  
  var field_choice;
  var is_mandatory = false;  
  
  if (!source.state.nil()) {
    field_choice = new GlideRecord('x_snd_eb_field_choice');
    field_choice.addQuery('table',         '=', 'incident');
    field_choice.addQuery('element',       '=', 'state');
    field_choice.addQuery('integration',   '=', '27be43a91b9db41090dfdb9ebd4bcb2e');
    field_choice.addQuery('field.message', '=', '');
    field_choice.addQuery('direction',     '=', 'Outbound');
    field_choice.addQuery('value',         '=', source.state);
    field_choice.addQuery('active',        '=', 'true');
    field_choice.query();
  
    if (field_choice.next()) {
      $stage.state = '' + field_choice.external_value;
    }
  } 
  
  if (!$stage.state) {
    $stage.state = '' + (source.state || '');
  }
  
  if (is_mandatory) {
    $stage.state = '' + (source.state || '');
  }

});

var error = x_snd_eb.ws_console.findCheckpointError("MessageScript");
if (error) throw error.message;

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

***Stage to Request:***

```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.checkpoint("MessageScript")

x_snd_eb.ws_console.execute("Mapping incident.number [x_snd_eb_field.do?sys_id=997a766c1be1bc1090dfdb9ebd4bcbb7]", function () {
  log.debug("Field map: PI - String [x_snd_eb_field_map.do?sys_id=da997f7a1b51b81090dfdb9ebd4bcb5e]");
  payload = payload || {};
  var $payload = payload;
  
  // Determines whether this instance of the field map is for a mandatory field
  var is_mandatory = false;
  
  if (is_mandatory) {
    $payload.correlation_id = '' + $stage.number;
  } else if ($stage.number) {
    $payload.correlation_id = '' + $stage.number;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.caller_id [x_snd_eb_field.do?sys_id=3a5cbbbe1b51b81090dfdb9ebd4bcb66]", function () {
  log.debug("Field map: PI - String [x_snd_eb_field_map.do?sys_id=da997f7a1b51b81090dfdb9ebd4bcb5e]");
  payload = payload || {};
  var $payload = payload;
  
  // Determines whether this instance of the field map is for a mandatory field
  var is_mandatory = false;
  
  if (is_mandatory) {
    $payload.caller_id = '' + $stage.caller_id;
  } else if ($stage.caller_id) {
    $payload.caller_id = '' + $stage.caller_id;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.short_description [x_snd_eb_field.do?sys_id=49debf3e1b51b81090dfdb9ebd4bcba5]", function () {
  log.debug("Field map: PI - String [x_snd_eb_field_map.do?sys_id=da997f7a1b51b81090dfdb9ebd4bcb5e]");
  payload = payload || {};
  var $payload = payload;
  
  // Determines whether this instance of the field map is for a mandatory field
  var is_mandatory = false;
  
  if (is_mandatory) {
    $payload.short_description = '' + $stage.short_description;
  } else if ($stage.short_description) {
    $payload.short_description = '' + $stage.short_description;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.description [x_snd_eb_field.do?sys_id=618a766c1be1bc1090dfdb9ebd4bcb91]", function () {
  log.debug("Field map: PI - String [x_snd_eb_field_map.do?sys_id=da997f7a1b51b81090dfdb9ebd4bcb5e]");
  payload = payload || {};
  var $payload = payload;
  
  // Determines whether this instance of the field map is for a mandatory field
  var is_mandatory = false;
  
  if (is_mandatory) {
    $payload.description = '' + $stage.description;
  } else if ($stage.description) {
    $payload.description = '' + $stage.description;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.state [x_snd_eb_field.do?sys_id=f32e8cc31b91b81090dfdb9ebd4bcb09]", function () {
  log.debug("Field map: PI - Choice [x_snd_eb_field_map.do?sys_id=c7b97f7a1b51b81090dfdb9ebd4bcb62]");
  payload = payload || {};
  var $payload = payload;
  
  var is_mandatory = false;  
  
  if (is_mandatory) {
    $payload.state = $stage.state;
  } else if ($stage.state) {
    $payload.state = $stage.state;
  }

});

var error = x_snd_eb.ws_console.findCheckpointError("MessageScript");
if (error) throw error.message;

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

We have now completed the configuration and are ready to move on to **Test** our Update Scenario.
