This section explains how to develop custom formatters to convert properties, and make them compatible with the properties of an OData service in the SAP Gateway system.
In some cases, you may need to develop a custom formatter that can map custom properties in Microsoft Outlook to the properties in an OData service.
The formatter then converts the Microsoft Outlook custom property to the property as known by the OData service, so that the expected data can be retrieved from the SAP system for end users.
To create a custom formatter, create a new class for the formatter and implement the IPropertyFormatter interface, which is provided in the GWM Outlook add-in project.
To open the Check Address dialog, from the menu choose , enter some text in the box beside Business and then select Map It in the Addresses pane.
For instance, to map the property, Country/Region (for example, Germany) in the Check Address dialog box, to the OData property, Country code (for example, DE) as required by the service, follow the steps below.
A new Class item is created.
Below are the methods of the IPropertyFormatter interface:
Interface Methods | Description |
---|---|
ConvertValue | This method will convert the value received from the SAP
system into the value as required by Microsoft Outlook. This
method takes in the values and returns the formatted
value. Example In case of CountryFormatter it will take in the country
code and return the country
description
|
ConvertValueBack | This method will convert the value received from Microsoft
Outlook into the value as required by the SAP system. This
method takes in the value and the target data type of the value
(such as, int, string…) and returns the formatted
value. Example In case of CountryFormatter it will
take in the country description and return the country
code
|
using System; using System.Collections.Generic; using System.Linq; using System.Text; using SAP.IW.GWM.Common.Configuration ; namespace GWPAM_Outlook_Addin1.Outlook.Formatter { class CountryFormatter : IPropertyFormatter { static List<GWDEMO.Country> CountryCodeList = null; static CountryFormatter() { CountryCodeList = new List<GWDEMO.Country>(); ServiceDetails serviceDetail = ConfigurationReaderHandler.Instance.GetServiceDetails("GWDEMO"); GWDEMO.GWDEMO context = new GWDEMO.GWDEMO(new Uri(serviceDetail.Url)); foreach(var country in context.CountryCollection) { CountryCodeList.Add(country); } } /// <summary> /// This method will convert the value from the country code as received in the service to the country Description as present in the country description drop down of outlook contact /// </summary> /// <param name="value">country code</param> /// <returns>country description</returns> public object ConvertValue(object value) { var country = CountryCodeList.FirstOrDefault(j => j.CountryCode == value.ToString()); string result = country == null ? value.ToString() : country.CountryText; return result; } /// <summary> /// This method will convert the value country description as received from outlook into the country code as required by the service /// </summary> /// <param name="value"></param> /// <param name="targetType"></param> /// <returns></returns> public object ConvertValueBack(object value, Type targetType) { var country = CountryCodeList.FirstOrDefault(j => j.CountryText == value.ToString()); string result = country == null ? value.ToString() : country.CountryCode; return result; } } }
We will initialize IPropertyFormatter interface with CountryFormatter class, and then invoke the method ConvertValue to convert the country code received from the OData service to the country description value in Microsoft Outlook contacts.