Show TOC

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

Binding the Sales Order Line Item with SAP Data.


The Sales Order Header was bound with SAP data in the section Binding the Sales Order Header with SAP Data, in this section the instructions are provided to bind the Sales Order Line Item for which we added colums in the section Adding Columns to the Sales Order Item Grid.
Note Close Microsoft Outlook before proceeding to execute the steps in this section.


  1. Right click on the DataGridView dgvSalesOrderHeader and click on Properties, to open the properties view.
  2. Click the Events Events_button button to display the events of the datagridview.
  3. Locate the CellClick row in the Properties list and double click on empty row adjacent to it.


    The cell click event is generated in the designer view, and the new click event willl be in focus.


In the dgvSalesOrderHeader_CellClick method, write the code to select the row of the dgvsalesorderheader grid and for the selected row, read the value of the property salesorderkey. The SalesOrderKey property is required to get the associated SalesOrderItem from the SAP System.

  1. Use the following code to perform the functions mentioned above:

private void dgvSalesOrderHeader_CellClick(object sender, DataGridViewCellEventArgs e)
            if (this.dgvSalesOrderHeader.SelectedRows != null && this.dgvSalesOrderHeader.SelectedRows.Count > 0 && this.dgvSalesOrderHeader.SelectedRows[0] != null && this.dgvSalesOrderHeader.SelectedRows[0].Index > -1)
                string salesorderkey = this.dgvSalesOrderHeader[this.EPM_SalesOrder_Note.Name, this.dgvSalesOrderHeader.SelectedRows[0].Index].Value.ToString();


  1. Right click on ShowSelectedSalesOrderItem(salesorderkey) in the above code and select Start of the navigation path Generate Next navigation step Method Stub End of the navigation path from the shortcut menu.
    This will generate an empty stub with the required signature in the AssociatedEntitiesTabMediator.
  2. In the Solution Explorer region, double click and open up the AssociatedEntitiesTabMediator class.
  3. Search for the method ShowSelectedSalesOrderItem.
  4. Replace the text throw new NotImplementedException with the code given below to fetch the associated SalesOrderItem from the SAP system.
    internal void ShowSelectedSalesOrderItem(string salesorderkey)
                Logger.Log(Severity.Verbose, Categories.Outlook_RelatedEntity, "AssociatedEntitiesTabMediator::ShowSelectedSalesOrderItem(salesorderkey="+salesorderkey+")");
                GWDEMO.GWDEMO serviceContext = null;
                    serviceContext = new GWDEMO.GWDEMO(new Uri(this.businessApplication.ServiceUrl));
                    string associatedEntityUrl = string.Format("{0}/SalesOrderCollection('{1}')/salesorderlineitems",this.businessApplication.ServiceUrl,salesorderkey);
                    Logger.Log(Severity.Info, Categories.Outlook_RelatedEntity, "Fetching SalesOrderItem records by querying {0}",associatedEntityUrl.Replace(businessApplication.ServiceUrl,""));
                    DataServiceQueryContinuation<GWDEMO.SalesOrderLineItem> token = null;
                    QueryOperationResponse<GWDEMO.SalesOrderLineItem> serviceresponse = serviceContext.Execute<GWDEMO.SalesOrderLineItem>(new Uri(associatedEntityUrl)) as QueryOperationResponse<GWDEMO.SalesOrderLineItem>;
                        if (token != null)
                            Logger.Log(Severity.Info, Categories.Outlook_RelatedEntity, "Server side paging enabled . Fetching next set of records for ShowSelectedSalesOrderItem");
                            serviceresponse = serviceContext.Execute<GWDEMO.SalesOrderLineItem>(token);
                        foreach (GWDEMO.SalesOrderLineItem entity in serviceresponse)
                            DataGridViewRow dataGridRow = new DataGridViewRow();
                            AddPropertyToGridRow(dataGridRow, entity.ProductID,"ProductID");
                            AddPropertyToGridRow(dataGridRow, entity.ProductName,"ProductName");
                            AddPropertyToGridRow(dataGridRow, entity.NetSum,"NetSum");
                            AddPropertyToGridRow(dataGridRow, entity.Tax,"Tax");
                            AddPropertyToGridRow(dataGridRow, entity.TotalSum,"TotalSum");
                            AddPropertyToGridRow(dataGridRow, entity.CurrencyCodeDescription,"CurrencyCodeDescription");
                            AddPropertyToGridRow(dataGridRow, entity.Availability,"Availability");
                            AddPropertyToGridRow(dataGridRow, entity.Note,"Note");
                         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 SalesOrderItems from backend for salesorederkey="+salesorderkey+".");
                    Logger.LogException(Severity.Error, Categories.Outlook_RelatedEntity, ex);
    			catch (DataServiceQueryException queryEx)
    				ExceptionHandler.LogAndShowException(queryEx, "DataServiceQueryException raised during fetching SalesOrderItems  from backend for salesorderkey="+salesorderkey+".");
                catch (DataServiceRequestException requestEx)
                    ExceptionHandler.LogAndShowException(requestEx, "DataServiceRequestException raised during fetching SalesOrderItems  from backendfor salesorderkey="+salesorderkey+".");
    			catch(System.Net.WebException webEx)
    				ExceptionHandler.LogAndShowException(webEx, "WebException raised during fetching SalesOrderItems  from backend for salesorderkey="+salesorderkey+".");
                catch (System.Exception ex)
    				if (ExceptionHandler.IsFatalException(ex))
                    Logger.Log(Severity.Error, Categories.Outlook_RelatedEntity, "Error while fetching the SalesOrderItems from backend and populating the grid");
                    Logger.LogException(Severity.Error, Categories.Outlook_RelatedEntity, ex);
  5. Search for the method PopulateGridEPM_SalesOrder in the AssociatedEntitiesTabMediator.cs.
  6. Add the following to code to the PopulateGridEPM_SalesOrder method to display the SalesOrderItems for the first row of the SalesOrderHeader when the EPM SalesOrder tab view is opened.
    string salesorderkey = this.dgvEPM_SalesOrder["EPM_SalesOrder_Note", 0].Value.ToString();

Verifying in Microsoft Outlook


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


  1. Open Microsoft Outlook, and navigate to the Contact folder (or the folder you had created in the wizard).
  2. Open any contact and navigate to the AssociatedEntities tab.
  3. Select the EPM SalesOrder tab.
  4. Click on any of the item from the SalesOrder header grid and the corresponding sales order items will be populated below. VerifySalesOrderItem