Message Scripts are where the request processing and data mapping occurs.

There are four different types of script which are used either before or after the Stage. Having these script types in relation to the Stage allows us to find any potential errors/discrepancies in data more easily.

  • Payload to Stage (Inbound)

    Data coming in is going to be translated (moved ‘as is’) from the Request to the Stage.

  • Source to Stage (Outbound)

    Data going out is going to be transformed (moved and changed) from the source to the Stage.

    The following example extract from the Source to Stage Message Script shows location data being mapped:

    if (!source.location.nil()) {
      stage.u_location_id = source.location.name;
      stage.u_address = source.location.street;
      stage.u_town = source.location.city;
      stage.u_county = source.state;
      stage.u_postcode = source.zip;
      stage.u_country = source.country;
      stage.region = source.region;
    }
    
  • Stage to Target (Inbound)

    Data coming in is going to be transformed (moved and changed) from the Stage to the target.

  • Stage to Request (Outbound)*

    Data going out is going to be translated (moved ‘as is’) from the Stage to the Request.

    *This script is not always necessary as the translation can also occur in the XML Template.

Bond State & Ownership

The Message Scripts are also the place where Bond state & ownership are set.

The following Stage to Target Message Script from the AcknowledgeCreateIncident Message sets the Bond state to Open:

(function processStageToTarget(target, stage, transaction, bond, log) {

  bond.setOpen();
  
})(target, stage, transaction, bond, log);

The following extract from the Stage to Target Message Script for a CreateIncident Message shows the ownership of the Bond is with the internal system target.u_ebond_owner = true;; therefore, Bond ownership cannot be with the external system bond.setValue('owner', false);. It also shows the source of the Bond being identified as the unique Integration with the external system sending the Message target.u_ebond_source = transaction.integration; (which can be particularly useful with multi-vendor integrations).

// If this incident is being created in your instance then likely you are the owner
// Bond owner is set to false, as it is referring to the other system
bond.setValue('owner', false);

// We also update custom fields on the target record itself (i.e. Incident) so things like ACL rules can be used to restrict access to the Incident fields.
target.u_ebond_owner = true;
target.u_ebond_source = transaction.integration;