Show TOC

Binding the Sales Order Header with SAP DataLocate this document in the navigation structure

Binding the Sales Order Header with SAP Data.


In GWM Visual Studio Add-In project, any calls made to the SAP system to populate the associated entities is handled through the Associated Mediator class. This section will guide you to use the associated mediator class to bind the Sales Order Header created in the Adding Columns to the Sales Order Header Grid section


  1. Open the Solution Explorer and expand Start of the navigation path EPM Accounts Next navigation step Outlook Next navigation step Contacts Next navigation step EPM Accounts Next navigation step AssociatedEntitiesTabMediator.cs End of the navigation path.
    Note The folder name EPM Accounts may vary depending on the application name provided during GWM Outlook project creation.
  2. Double click on AssociatedEntitiesTabMediator.cs to open it.
  3. Expand the private member region in the class, and declare the variable to store the sales order header and item grid using the following code
    private DataGridView dgvEPM_SalesOrder;
    private DataGridView dgvEPM_SalesOrderItem;
    private ContactItem outlookItem;
  4. Search for the method AssociatedEntitiesTabMediator and then navigate directly to the constructor.

The AssociatedEntitiesMediator needs to have access to the UI.

  1. Change the signature of the AssociatedEntitiesTabMediator constructor to accept parameter values for dgvsalesorderheader and dgvsalesorderitem, and assign it to the respective data members declared in the previous steps.
    /// <summary>
    /// This is method sets the datagrid view of the mediator
    /// </summary>
    /// <param name="dgvEPM_Contacts"></param>;
    internal AssociatedEntitiesTabMediator(DataGridView dgvEPM_Contacts,DataGridView dgvEPM_SalesOrder,DataGridView dgvEPM_SalesOrderItem)
    Logger.Log(Severity.Verbose, Categories.Outlook_RelatedEntity, "AssociatedEntitiesTabMediator::Constructor()");
    this.dgvEPM_Contacts = dgvEPM_Contacts;
    this.dgvEPM_SalesOrder = dgvEPM_SalesOrder;
    this.dgvEPM_SalesOrderItem = dgvEPM_SalesOrderItem;
    this.dgvEPM_Contacts.Columns[this.dgvEPM_Contacts.ColumnCount - 1].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
                this.dgvEPM_SalesOrder.Columns[this.dgvEPM_SalesOrder.ColumnCount - 1].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
                this.dgvEPM_SalesOrderItem.Columns[this.dgvEPM_SalesOrderItem.ColumnCount - 1].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
  2. Search for the method SetBusinessApplication.
  3. Comment out the line:
    ContactItem outlookItem = null;
  4. To fill the datagrid for the SalesOrderHeader, we need to query for the SalesOrderHeader collection and filter the values on the basis of the customerid property of the EPM Accounts:
    1. Query for the contactId user property from the selected contact.
    2. Trigger the OData call through our generated proxy to query SalesOrder collection where customerid property is equal to the contact item’s id.
    3. Bind the filtered response data to the dgvSalesOrderHeader datagrid.

Use this code to execute the above steps:

#region Populate Grid EPM_SalesOrder Helper
 /// <summary>
 /// This method will populate the EPM_SalesOrder tab regions
/// </summary>
internal void PopulateGridEPM_SalesOrder()
            Logger.Log(Severity.Verbose, Categories.Outlook_RelatedEntity, "AssociatedEntitiesTabMediator::PopulateGridEPM_SalesOrder()");
            GWDEMO.GWDEMO serviceContext = null;
            UserProperties userProperties = null;
            UserProperty userProperty = null;
            string customerID = "";
                serviceContext = new GWDEMO.GWDEMO(new Uri(this.businessApplication.ServiceUrl));
                DataServiceQueryContinuation<GWDEMO.SalesOrder> token = null;
                QueryOperationResponse<GWDEMO.SalesOrder> serviceresponse = serviceContext.SalesOrderCollection.Execute() as QueryOperationResponse<GWDEMO.SalesOrder>;

                userProperties = outlookItem.UserProperties;
                userProperty = userProperties[OutlookUtilities.GetUserPropertyName("BusinessPartnerID")];
                if (userProperty != null)
                    if (!string.IsNullOrEmpty(userProperty.Value))
                        customerID = userProperty.Value;

                    if (token != null)
                        Logger.Log(Severity.Info, Categories.Outlook_RelatedEntity, "Server side paging enabled . Fetching next set of records for EPM_SalesOrder");
                        serviceresponse = serviceContext.Execute<GWDEMO.SalesOrder>(token);
                    foreach (GWDEMO.SalesOrder entity in serviceresponse)
                        if (entity.CustomerID == customerID)
                            DataGridViewRow dataGridRow = new DataGridViewRow();
                            AddPropertyToGridRow(dataGridRow, entity.SalesOrderID,"SalesOrderID");
                            AddPropertyToGridRow(dataGridRow, entity.CustomerID,"CustomerID");
                            AddPropertyToGridRow(dataGridRow, entity.CustomerName,"CustomerName");
                            AddPropertyToGridRow(dataGridRow, entity.NetSum,"NetSum");
                            AddPropertyToGridRow(dataGridRow, entity.Tax,"Tax");
                            AddPropertyToGridRow(dataGridRow, entity.TotalSum,"TotalSum");
                            AddPropertyToGridRow(dataGridRow, entity.CurrencyCodeDescription,"CurrencyCodeDescription");
                            AddPropertyToGridRow(dataGridRow, entity.StatusDescription,"StatusDescription");
                            AddPropertyToGridRow(dataGridRow, entity.Note,"Note");
                            AddPropertyToGridRow(dataGridRow, entity.SalesOrderKey,"SalesOrderKey");

                    this.customTabResponseState[1] = true;
SAP.IW.SSO.Supportability.SingleActivityTraceUtil.Instance.UpdateRequestForSAT(serviceresponse.Headers, serviceresponse.StatusCode, serviceresponse.Query.RequestUri.ToString());

                while ((token = serviceresponse.GetContinuation()) != null);
            catch (SSOException ex)
                ExceptionHandler.ShowMessage(ResourceManager.GetLocalizedText("UserAuthentication_Error", Constants.ErrorMessages));
                Logger.Log(Severity.Error, Categories.Outlook_RelatedEntity, "SSOException raised during fetching ContactPerson items from backend while populating tab EPM_SalesOrder.");
                Logger.LogException(Severity.Error, Categories.Outlook_RelatedEntity, ex);
            catch (DataServiceQueryException queryEx)
                ExceptionHandler.LogAndShowException(queryEx, "DataServiceQueryException raised during fetching ContactPerson items from backend while populating tab EPM_SalesOrder.");
            catch (DataServiceRequestException requestEx)
                ExceptionHandler.LogAndShowException(requestEx, "DataServiceRequestException raised during fetching ContactPerson items from backend while populating tab EPM_SalesOrder.");
            catch (System.Net.WebException webEx)
                ExceptionHandler.LogAndShowException(webEx, "WebException raised during fetching ContactPerson items from backend while populating tab EPM_SalesOrder.");
            catch (System.Exception ex)
                if (ExceptionHandler.IsFatalException(ex))
                Logger.Log(Severity.Error, Categories.Outlook_RelatedEntity, "Error while fetching the ContactPerson values from backend and populating the grid");
                Logger.LogException(Severity.Error, Categories.Outlook_RelatedEntity, ex);

  1. Search for the method LoadAssociatedTaband then extend the switch statement to handle the newly added tab page using the code below:
    internal void LoadAssociatedTab(int selectedTabIndex)
                if (!this.customTabResponseState[selectedTabIndex])
                    Cursor.Current = Cursors.WaitCursor;
                    switch (selectedTabIndex)
                        case 0:
    		         Logger.Log(Severity.Info, Categories.Outlook_RelatedEntity, "Loading Selected Custom tab: EPM_Contacts");
                        case 1:
                            Logger.Log(Severity.Info, Categories.Outlook_RelatedEntity, "Loading Selected Custom tab: EPM_SalesOrder");
                    Cursor.Current = Cursors.Default;
  2. Right click on the AssociatedEntitiesTab and select the option View Code, and follow the steps below to connect the custom tabs with the mediator code:
    1. Replace the line:
      this.mediator = new AssociatedEntitiesTabMediator(this.dgvEPM_Contacts);


      this.mediator = new AssociatedEntitiesTabMediator(this.dgvEPM_Contacts,this.dgvSalesOrderHeader,this.dgvSalesOrderItem);

Verifying in Microsoft Outlook


Perform this step on a system where Microsoft Outlook Profession edition is installed


  1. Build and run the code to launch the Microsoft Outlook.
    Note Clear up any previous EPM Accounts from the Microsoft Outlook test system before testing this functionality.
  2. Navigate to the GWM ribbon and click on Get All to get the filtered list of records from the SAP system.
  3. Navigate to the Contact folder, and open any EPM Account, for example, SAP.
  4. Double click on the contact to open it.
  5. Navigate to the AssociatedEntities tab, and then click on the EPM SalesOrder tab. SAP_Contacts
    The EPM SalesOrder displays the selected contacts accounts details from the SAP system.