Below is the code I'm working with to pass multiple line items to create sales order through GP Web service. I can pass single Line Item without any problem , but when I pass multiple Items it is only taking the last one. The array has around 5 Item ID and I'm passing fixed Quantity as 15, Need to make both dynamic. But for the testing purpose I'm trying like this. I know the problem with the creation/initialization of some web service objects. As novice to the entire set of things I couldn't find the exact problem.
CompanyKey companyKey; Context context; SalesOrder salesOrder; SalesDocumentTypeKey salesOrderType; CustomerKey customerKey; BatchKey batchKey; SalesOrderLine salesOrderLine; ItemKey orderedItem; Quantity orderedAmount; Policy salesOrderCreatePolicy; DynamicsGPClient wsDynamicsGP = new DynamicsGPClient(); wsDynamicsGP.ClientCredentials.Windows.ClientCredential.UserName = "Admin"; wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Password = "PWd"; wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Domain = "GP"; System.ServiceModel.WSHttpBinding binding; binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None); context = new Context(); companyKey = new CompanyKey(); companyKey.Id = (1); context.OrganizationKey = (OrganizationKey)companyKey; salesOrder = new SalesOrder(); salesOrderType = new SalesDocumentTypeKey(); salesOrderType.Type = SalesDocumentType.Order; salesOrder.DocumentTypeKey = salesOrderType; customerKey = new CustomerKey(); customerKey.Id = "121001"; salesOrder.CustomerKey = customerKey; batchKey = new BatchKey(); batchKey.Id = "RMS"; salesOrder.BatchKey = batchKey; SalesOrderLine[] orders = new SalesOrderLine[6]; for (int i = 1; i < 3; i++) { orderedItem = new ItemKey(); orderedItem.Id = Arr[i].ToString(); salesOrderLine = new SalesOrderLine(); salesOrderLine.ItemKey = orderedItem; orderedAmount = new Quantity(); orderedAmount.Value = 15; salesOrderLine.Quantity = orderedAmount; orders[i] = salesOrderLine; } salesOrder.Lines = orders; salesOrderCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesOrder", context); wsDynamicsGP.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy); if (wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } MessageBox.Show("Success");
*This post is locked for comments