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
The AssociatedEntitiesMediator needs to have access to the UI.
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 = ""; try { 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; } OutlookUtilities.CleanUpResources(userProperty); } do { 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.dgvEPM_SalesOrder.Rows.Add(dataGridRow); } } 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)) { throw; } 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); } } #endregion