Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Passing multiple line items with GP web service CreateSalesorder

(0) ShareShare
ReportReport
Posted on by

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

  • Tim Wappat Profile Picture
    5,703 on at
    RE: Passing multiple line items with GP web service CreateSalesorder

    Should your loop not be zero indexed with five items:

    (int i = 0; i < 6; i++)

    But i doubt that is the problem.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans