How to Synchronize Different Field Types on ServiceNow

    This article shows how to synchronize ServiceNow fields of different types.

    In ServiceNow, you can get and set any of the fields of the entity by its internal name. For example:

    • get the state of an incident

      def state = incident.incident_state
    • set a value to the incident state field manually 

      incident.incident_state = "9"

    Exalate maps the field names and values to the ServiceNow Rest API, which means that any field name/value that is allowed by the Rest API would work when used from the Exalate groovy scripts.

    • ServiceNow to Jira
    • Jira to ServiceNow
    • ServiceNow to ServiceNow

    ServiceNow to Jira

    Source side(ServiceNow)

    Outgoing sync

    Send a field value

    You should use the column name instead of the field.

     replica.short_description = incident.short_description

    Destination Side (Jira)

    Incoming sync

    Set the value received from ServiceNow to the Jira custom field with the issue.customFields."Jira Custom Field name".value variable.

     issue.customFields."Jira Custom Field name".value = replica.short_description

    Jira to ServiceNow

    Source side(Jira)

    Outgoing sync

    Send the Jira custom field value without any context to the ServiceNow side

    replica.customFields."Jira Custom Field name" = issue.customFields."Jira Custom Field name"

    Destination Side (ServiceNow)

    Incoming sync

    When setting received value from Jira custom field you need to know the type of the local field.

    Fields of type String

    Set the received value from the Jira custom field into the field of type String

    You should use the column name instead of the field.

    incident."short_description" = replica.customFields."Jira Custom Field name".value

    Fields of type reference

    To set the value received from the Jira custom field into the field of type reference you need to retrieve the field from ServiceNow API using getTableByName helper method.

    incident."assignment_group" = nodeHelper.getTableByName("assignment_group", replica.customFields."Jira Custom Field name".value)?.sys_id

    in some cases, you are able to set a reference field by the display name value:

    incident."assignment_group" = replica.customFields."Jira Custom Field name"?.value

    ServiceNow to ServiceNow

    Source side(ServiceNow)

    Outgoing sync

    Send a field

    You need to use the column name instead of the display name. Check how to find the column name of a ServiceNow field for more details.

    replica.short_description = incident.short_description

    Destination Side (ServiceNow)

    Incoming sync

    Fields of type String

    To synchronize an individual field of the same type

    You should use the column name instead of the field.

    incident.short_description = replica.short_description

    You can set a value from one field to another field when creating the ServiceNow incident(or any other supported entity) using this example. It helps to append the string value to another field.

    incident."Service Now Field Name" = "My value" + incident."Field 2 Name"