How to Customise Movement Message Formats using Custom Values

In some cases the variables used in the Arrival and Departure movement message templates are not formatted as required.
For example, some clients prefer for the movement messages to closer resemble the IATA format.

Example 1:

The below movement message shows the On-block time in the format dd-mmm-yy hh:mm

MVT 
RCH145/18.68159.BIKF 
AA 180018-Apr-16 18:04 (UTC)
REMARKS - 
AC TYPE C130 
OPERATOR USAF Air Mobility Operations 
ORIGIN EGAA 
HANDLING ORDER ID KEF-5401

The movement message needs to be changed so that both the ATA and on-block times are in the format HHMM, as follows:

MVT 
RCH145/18.68159.BIKF 
AA 1800/1804
REMARKS - 
AC TYPE C130 
OPERATOR USAF Air Mobility Operations 
ORIGIN EGAA 
HANDLING ORDER ID KEF-5401

Step 1

There is no variable available to show the on-block time in the above required format and therefore a custom value must be setup to allow this.
Go to Administration > Custom Values and create a new one such as OnBlocksTimeUtc


Once saved use the 'Add new' button to create a value. The below formula can be copied and inserted into the 'formula' field.

The format HHMM as required for the movement message, is stated in the below formula


   ((Func<string>)(() => {
      {
        var onBlockText = (string)input.GetTemplateValue("ArrivalOnBlocksDateTimeUtc");
        var indexUtc = onBlockText.IndexOf("(UTC)");
        if (indexUtc > 0)
        {
          DateTime onBlock;
          if (DateTime.TryParse(onBlockText.Substring(0, indexUtc), out onBlock))
            return $"{ onBlock:HHmm}";
        }
        return "";
      }
    }))();


Finally, under the section 'Tables applicable to the custom property selected above' use the 'add new' button to link the custom value to the 'Order' table.

Step 2

The custom value must now be inserted into the email body for the setting 'ArrivalNotificationEmailBody'.

The variable to be inserted uses the format ~Custom-CustomPropertyName~.
In this example the Custom Property Name is OnBlocksTimeUtc:

Therefore the format for the variable is ~Custom-OnBlocksTimeUtc~

The arrival movement message has now been successfully changed to show the on block time in format HHMM

Other Useful Formulas

Off Blocks Time in UTC displayed as HHmm
Custom Value: OffBlocksTimeUtc

Custom Value: OffBlocksTimeUtc
((Func<string>)(() => {
      { 
        var offBlocksText = (string)input.GetTemplateValue("DepartureOffBlocksDateTimeUtc");
        var indexOfUtc = offBlocksText.IndexOf("(UTC)");
        if (indexOfUtc > 0)
        {
          DateTime offBlocks;
          if (DateTime.TryParse(offBlocksText.Substring(0, indexOfUtc), out offBlocks))
            return $"{ offBlocks:HHmm}";
        }
        return "";
      }
    }))();


ETA at Destination displayed as HHmm - e.g. 1055
Custom Value: EtaAtDestination 

Custom Value: EtaAtDestination
((Func<string>)(() => {{ 
var dateFormat = "HHmm";
var etaAtDestinationUtc = (DateTime?)input.GetOrderField("EtaAtDestinationUtc");
return etaAtDestinationUtc.HasValue ? etaAtDestinationUtc.Value.ToString(dateFormat).ToUpper() : "";
}}))();


ETA at Destination displayed as dd-mmm-yy HH:mm, in Uppercase and followed by 'UTC' - e.g. 02-AUG-16 16:20 UTC
Custom Value: EtaAtDestination

Custom Value: EtaAtDestination
((Func<string>)(() => {{
var dateFormat = "dd-MMM-yy HH:mm UTC";
var etaAtDestinationUtc = (DateTime?)input.GetOrderField("EtaAtDestinationUtc");
return etaAtDestinationUtc.HasValue ? etaAtDestinationUtc.Value.ToString(dateFormat).ToUpper() : "";
}}))();


ATD UTC displayed as dd-mmm-yy HH:mm, in Uppercase and followed by 'UTC' - e.g. 02-AUG-16 12:50 UTC

CustomValue: AtdUtcFormatted

Custom Value: AtdUtcFormatted
((Func<string>)(() => {{
var dateFormat = "dd-MMM-yy HH:mm UTC";
var MostActualDepartureDateTime = (DateTime?)input.GetOrderField("MostActualDepartureDateTime");
return MostActualDepartureDateTime.HasValue ? MostActualDepartureDateTime.Value.ToString(dateFormat).ToUpper() : "";
}}))();

NOTE:

The above two formulas contain .ToUpper() on the last line. This ensures the Custom Value shows in Upper case.
For the output to be for example '02-Aug-16 13:50 UTC' the .ToUpper () section is removed from the above formulas - i.e. as below

ETA At Destination / Format e.g, 02-Aug-16 13:50 UTC
((Func<string>)(() => {{
var dateFormat = "dd-MMM-yy HH:mm";
var etaAtDestinationUtc = (DateTime?)input.GetOrderField("EtaAtDestinationUtc");
return etaAtDestinationUtc.HasValue ? etaAtDestinationUtc.Value.ToString(dateFormat) :"";
}}))();


Creating New Formulas:
To help create new formulas use the above examples as a basis and the Orders query page > 'Available Fields' section, to find the correct 'var' to insert on lines 3 and 4 of the formula


See Also
ArrivalNotificationEmailBody & DepartureNotificationEmailBody 
How to create an Order calculated custom value using C# formulas 
Email template variables 
Orders query 
How to show the Bag-Count in the Arrrival/Departure screen & Movement Messages