---
description: >-
  We will utilise the Field & Field Map records to configure the Message Scripts
  for the ResolveIncident Message.
---

# ResolveIncident Fields

The 'incident.comments', 'incident.work\_notes' and 'incident.short\_description' Field records are already in place because they were also copied when we copied the Message. We can choose to include, or exclude as many of those and the Integration level ones that are available depending on our requirements (by either activating or deactivating the relevant Fields). We will choose to keep the existing Message level Fields and add the available incident.state (Integration level) Field.

## Field: incident.state (Message level)

By simply setting the Active flag to true on the Integration level Field record listed on the Message, Unifi will automatically create the Message level counterpart.

Navigate to **Message > Fields**.

_Your ResolveIncident Message Fields page should look like this:_

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-MeyoyBC7RzHU1GwzbQa%2FOBIG%20-%20ResolveIncident%20Fields%201.png?alt=media\&token=e146adac-3677-45ef-bfa1-039d65237e28)

Find the **incident.state** (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)_.
{% endhint %}

We will now configure Field records for the two remaining Incident record field elements which are required.

## Fields & Field Maps

The table below lists the Incident record field elements we will map and the relevant Field Maps required to configure each Field record.

| Incident Field | Field Map       |
| -------------- | --------------- |
| close\_code    | 'PI - Choice'\* |
| close\_notes   | 'PI - String'\* |

_\*Field map: Values may vary (dependent on your configuration of the copies). Choose the copy Field Maps you created earlier._

## Field: incident.close\_code (Message level)

{% hint style="info" %}
There is no need to 'Generate field choices' for Message level Field records because the Field Map always looks for them on an Integration level Field which has the same name.
{% endhint %}

As with 'incident.state' the 'incident.close\_code' Field record is a Choice 'type' Field. We will, therefore, configure the choices once at the Integration level. We'll first configure the Message level Field and then move on to configure the choices on its Integration level counterpart.

From the Fields page, click **New**.

The fields to be configured for our incident.close\_code (Message level) New Field modal are as follows:

<table><thead><tr><th width="180.6910230078214">Field</th><th width="309.6240962450439">Description</th><th>Value</th></tr></thead><tbody><tr><td>Message*</td><td>The Message this Field record is linked with.</td><td>'ResolveIncident'</td></tr><tr><td>Description</td><td>The description of this Field record.</td><td>'The incident's Resolution code (Close code in ServiceNow)'</td></tr><tr><td>Active*</td><td>Set to true to use this Field record for processing.</td><td>&#x3C;true></td></tr><tr><td>Field map</td><td>The Field Map this Field record is linked with.</td><td>'PI - Choice'**</td></tr><tr><td>Map to field*</td><td>Use this Field record to represent a field on a source/target table.</td><td>&#x3C;true></td></tr><tr><td>Table*</td><td>The primary source/target table that this Field record is mapped to.</td><td>'Incident' [incident]</td></tr><tr><td>Element</td><td>The field on the source/target table this Field record is mapped to.</td><td>'Resolution code'</td></tr><tr><td>Property*</td><td>The property in the payload the data will be written to.</td><td>Automatically populated</td></tr><tr><td>Inbound*</td><td>Set to true to use for inbound Messages.</td><td>&#x3C;false></td></tr><tr><td>Outbound*</td><td>Set to true to use for outbound Messages.</td><td>&#x3C;true></td></tr><tr><td>Mandatory</td><td>Set to true to make mandatory.</td><td>&#x3C;true></td></tr></tbody></table>

_\*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.close\_code' (Message level) New Field modal should look like this:_

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-MeyrUq3_QmmLBcMeqTm%2FOBIG%20-%20ResolveIncident%20Fields%202.png?alt=media\&token=c74b3e6f-9d2d-4512-a6a2-7df0fc0a8347)

**Submit** the record.

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

## Field: incident.close\_code (Integration level)

{% hint style="info" %}
We will need to 'Generate field choices' for this Integration level Choice 'type' Field.
{% endhint %}

Navigate to the **'Fields' icon** to open the Fields page.

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-MeysC9uthTiqurJ_7kn%2FOBIG%20-%20ResolveIncident%20Fields%203.png?alt=media\&token=c5147f30-57ea-4117-b3e4-97e5403378a2)

Click to open the **incident.close\_code** (Integration level) Field record _(the one where Message is empty)_.

The incident.close\_code Field record opens to the Details page.

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-MeytZSzyGGl5bShzTTf%2FOBIG%20-%20ResolveIncident%20Fields%204.png?alt=media\&token=122fe414-34bf-495b-b5ad-610a6d06c510)

Navigate to **Field > Field Choices**.

Click **Generate field choices**.

Click **Generate** on the 'Generate field choices' modal which displays.

The Field Choices are generated & now visible in the list.

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-MeyuoMoTRIoVZRbaE7O%2FOBIG%20-%20ResolveIncident%20Fields%205.png?alt=media\&token=152124bd-00c4-44da-acfc-b965a627f5f6)

## Field: incident.close\_notes

Because the incident.close\_notes Field record is the same 'type' _(PI - String)_ & the majority of the settings are the same as the incident.work\_notes Field, it will be quicker to copy that Field & make a few minor changes.

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

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-Meywa3t7wDVc2CT-AlF%2FOBIG%20-%20ResolveIncident%20Fields%206.png?alt=media\&token=2d6cc2ec-a75d-4916-9940-0effed56c5cc)

Click the **ellipsis** next to the **incident.work\_notes** Field record & click **Copy**.

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

<table><thead><tr><th width="176.87900956668543">Field</th><th width="294.17954466699615">Description</th><th>Value</th></tr></thead><tbody><tr><td>Element</td><td>The field on the source/target table this Field record is mapped to.</td><td>'Resolution notes'</td></tr><tr><td>Property*</td><td>The property in the payload the data will be written to.</td><td>Automatically populated</td></tr><tr><td>Description</td><td>The description of this Field record.</td><td>'The incident's Resolution notes (Close notes in ServiceNow)'</td></tr></tbody></table>

_\*This field is automatically populated._

_Your 'incident.close\_notes' Copy Field modal should look like this:_

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-Meyxfxj6HBgTvd_u19r%2FOBIG%20-%20ResolveIncident%20Fields%207.png?alt=media\&token=8b5fde05-490c-4819-bb68-26915c9410d5)

Click **Copy**.

You will be redirected to the Details page of the newly created incident.close\_notes Field record.

The "This message inherits its configuration from the integration-level field..." info message is also displayed _(which can be closed)_.

{% hint style="info" %}
Field inheritance is set to true by default.  This means the record will be updated with integration-level Field values when saved (except for Active, Inherit and Message values). &#x20;

You can either uncheck the Inherit field to configure locally, or edit the integration-level Field record.  We will choose to edit the integration-level because it makes more sense to have the same settings for each message-level incident.close\_notes Field _(i.e. each will be mandatory)_.

For more information on Field Inheritance click [here](../../../../configuration/fields#inheritance).
{% endhint %}

Navigate to the **'Fields' icon** to open the Fields page.

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-Mez0uie5kUY5zdHsG3f%2FOBIG%20-%20ResolveIncident%20Fields%208.png?alt=media\&token=187788c5-07c0-48ea-a94b-4c43fbdbc4c8)

Click to open the **incident.close\_notes** (Integration level) Field record _(the one where Message is empty)_.

The incident.close\_notes Field record opens to the Details page.

Navigate to **Field > Settings**.

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-MezARfqAU8Yw_KuBmMy%2FOBIG%20-%20ResolveIncident%20Fields%209.png?alt=media\&token=251777c4-fa0b-4551-9f4b-af89c673d3cd)

Set **Mandatory** to **true**.

Click **Save**.

## Build

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

Navigate to the **ResolveIncident** message, then navigate to **Message > Fields**.

_The following Field records should now be in place for your ResolveIncident messsage:_

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-MezC3vZBtDXqZOEYAKd%2FOBIG%20-%20ResolveIncident%20Fields%2010.png?alt=media\&token=9617f808-5c10-48a0-8654-d0a1bcc957f8)

Click on **Build Message**.

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

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MQqoiX6GB0sHMigNIbe%2F-MQr5b1VoidEUbtJDN5H%2FV2%20-%20Fields%20-%20ResolveIncident%2010.png?alt=media\&token=14fe750c-daee-4c58-9c12-97bcd2e1a822)

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

_Your Script Editor fields should look like this:_

![](https://605238050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQBk35gIi557UHt7QlJ%2F-MeydynYUo8sQTU9KkIW%2F-MezC_Y5vrAKXq057Do0%2FOBIG%20-%20ResolveIncident%20Fields%2011.png?alt=media\&token=ca9daa09-9243-402f-8cf8-8e1714102a5e)

## 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.

_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.short_description [x_snd_eb_field.do?sys_id=06fe6b771b193c1090dfdb9ebd4bcbe0]", 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.state [x_snd_eb_field.do?sys_id=f2db33f71b193c1090dfdb9ebd4bcbc5]", 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 || '');
  }

});


x_snd_eb.ws_console.execute("Mapping incident.comments [x_snd_eb_field.do?sys_id=79fe6b771b193c1090dfdb9ebd4bcbcd]", 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.comments = '' + (source.comments || default_value);
  } else if (source.comments != '') {
    $stage.comments = '' + source.comments;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.work_notes [x_snd_eb_field.do?sys_id=4efe6b771b193c1090dfdb9ebd4bcbd1]", 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.work_notes = '' + (source.work_notes || default_value);
  } else if (source.work_notes != '') {
    $stage.work_notes = '' + source.work_notes;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.close_code [x_snd_eb_field.do?sys_id=eaaff7bb1b193c1090dfdb9ebd4bcb6f]", 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 = true;  
  
  if (!source.close_code.nil()) {
    field_choice = new GlideRecord('x_snd_eb_field_choice');
    field_choice.addQuery('table',         '=', 'incident');
    field_choice.addQuery('element',       '=', 'close_code');
    field_choice.addQuery('integration',   '=', '27be43a91b9db41090dfdb9ebd4bcb2e');
    field_choice.addQuery('field.message', '=', '');
    field_choice.addQuery('direction',     '=', 'Outbound');
    field_choice.addQuery('value',         '=', source.close_code);
    field_choice.addQuery('active',        '=', 'true');
    field_choice.query();
  
    if (field_choice.next()) {
      $stage.close_code = '' + field_choice.external_value;
    }
  } 
  
  if (!$stage.close_code) {
    $stage.close_code = '' + (source.close_code || '');
  }
  
  if (is_mandatory) {
    $stage.close_code = '' + (source.close_code || '');
  }

});


x_snd_eb.ws_console.execute("Mapping incident.close_notes [x_snd_eb_field.do?sys_id=0bd508401b693c1090dfdb9ebd4bcb5a]", 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 = true;
  
  if (is_mandatory) {
    $stage.close_notes = '' + (source.close_notes || default_value);
  } else if (source.close_notes != '') {
    $stage.close_notes = '' + source.close_notes;
  }

});

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.short_description [x_snd_eb_field.do?sys_id=06fe6b771b193c1090dfdb9ebd4bcbe0]", 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.state [x_snd_eb_field.do?sys_id=f2db33f71b193c1090dfdb9ebd4bcbc5]", 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;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.comments [x_snd_eb_field.do?sys_id=79fe6b771b193c1090dfdb9ebd4bcbcd]", 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.comments = '' + $stage.comments;
  } else if ($stage.comments) {
    $payload.comments = '' + $stage.comments;
  }

});


x_snd_eb.ws_console.execute("Mapping incident.work_notes [x_snd_eb_field.do?sys_id=4efe6b771b193c1090dfdb9ebd4bcbd1]", 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.work_notes = '' + $stage.work_notes;
  } else if ($stage.work_notes) {
    $payload.work_notes = '' + $stage.work_notes;
  }

});


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

});


x_snd_eb.ws_console.execute("Mapping incident.close_notes [x_snd_eb_field.do?sys_id=0bd508401b693c1090dfdb9ebd4bcb5a]", 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 = true;
  
  if (is_mandatory) {
    $payload.close_notes = '' + $stage.close_notes;
  } else if ($stage.close_notes) {
    $payload.close_notes = '' + $stage.close_notes;
  }

});

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

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

We are now ready to **Test** the **ResolveIncident** Message.
