Messages

A Message contains all the configuration required to send, receive, and process a request.

Messages are central to the functionality of Unifi. A Message brings together the disparate parts necessary for the configuration required in order to send, receive and process a request.

Message Fields

The Message fields to be configured for the Message record are as follows:

Configuration Fields

The Configuration fields to be configured for the Message record are as follows:

*Direction choices: Inbound, outbound, or bidirectional.

Trigger Fields

The Trigger fields to be configured for the Message record are as follows:

*Send to self:

By default, if an integration updates a target record it will not trigger messages to be sent back to itself, preventing feedback loops.

*Advanced condition:

This field is made visible when the 'Use advanced condition' field is set to true.

*Attachment added:

This field is made visible when the 'Send attachments' field is set to true.

Bond Fields

The Bond fields to be configured for the Message record are as follows:

*Bond ownership choices: Ignore, Must own, Must not own.

Scripts Fields

The Scripts fields to be configured for the Message record are as follows:

*Extract attachments script

This field is made visible when the Extract attachments box is checked. The script must always return a string and if an object is used it needs to be JSON encoded (i.e. JSON.stringify()). The following is an example:

payload = (function extractAttachments(payload, request) {
	
	// Convert from string to object
	var obj = JSON.parse(payload);
	
	// Extract the attachment here...
	
	// Update the payload
	payload = {
		attachment: ''
	};
	
	// Encode payload back to string
	return JSON.stringify(payload);
})(payload, request);

CDATA

It is possible to use CDATA within an XML message, but because of the way ServiceNow handles XML it can be a little bit tricky. When ServiceNow see’s the CDATA tag, it actually processes it and the tag ends up being removed in the final. We need to use a little trick allow us to actually get the CDATA in the final result.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
  <g:evaluate jelly="true">
    var stage = jelly.jvar_stage, transaction = jelly.jvar_transaction;

    // initiate the attachment sender
    var sender = new x_snd_eb.AttachmentSender(
      jelly.jvar_transaction,
      jelly.jvar_bond
    );

    // we only handle one attachment - use in while loop if there are many
    sender.next();

    // we need CDATA to not be processed by XML
    // It's added in the XML below to wrap the embedded document
    var cdata = [
      '&lt;![' + 'CDATA[&lt;?xml version="1.0"?&gt;',
      ']]&gt;'
    ];
  </g:evaluate>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://www.wsdl.com">
    <soapenv:Header/>
    <soapenv:Body>
      <wsdl:Request>
        <wsdl:RequestElement>
          <wsdl:server>dev.server.com</wsdl:server>
          <wsdl:formName>Attachment</wsdl:formName>
          <wsdl:id>ABC123</wsdl:id>
          <wsdl:xmlString>${cdata[0]}
            <Elements>
              <Element>
                <Name>Description</Name>
                <Value>Attachment Received from customer</Value>
              </Element>
              <Element>
                <Name>AttachmentName</Name>
                <Value>${HTML:sender.attachment_name}</Value>
              </Element>
              <Element>
                <Name>AttachmentData</Name>
                <Value><x-attachment-data sys_id="${sender.attachment_id}" /></Value>
              </Element>
            </Elements>${cdata[1]}</wsdl:xmlString>
          </wsdl:RequestElement>
        </wsdl:Request>
    </soapenv:Body>
  </soapenv:Envelope>
</j:jelly>

Last updated