web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

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

I have the same question (0)
  • Tim Wappat Profile Picture
    5,713 on at

    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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans