CreateSalesOrder


Description

This method creates a new sales order.

Parameters

Parameter

Type

Description

salesOrder

SalesOrder

The sales order object being created.

context

Context

Specifies information about how the method will be called.

policy

Policy

Specifies the set of behaviors and behavior options to be applied during the operation.


Interfaces

 

Examples

The following C# example creates a sales order. The example first populates the required DocumentTypeKey, CustomerKey, and BatchKey properties. The sales order uses a sales order line to specify the item and quantity ordered. The sales order line requires the ItemKey, and Quantity properties to be populated. The sales order key and sales order line key are not populated. The CreateSalesOrder operation automatically populates the empty sales order key and sales order line key with the next available order number. All other sales order properties are set to default values. The CreateSalesOrder operation saves the new sales order.

 Legacy endpoint

using System;
using System.Collections.Generic;
using System.Text;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			SalesOrder salesOrder;
			SalesDocumentTypeKey salesOrderType;
			CustomerKey customerKey;
			BatchKey batchKey;
			SalesOrderLine salesOrderLine;
			ItemKey orderedItem;
			Quantity orderedAmount;
			Policy salesOrderCreatePolicy;

			// Create an instance of the service
			DynamicsGP wsDynamicsGP = new DynamicsGP();

			// Be sure the default credentials are used
			wsDynamicsGP.UseDefaultCredentials = true;

			// Create a context with which to call the service
			context = new Context();

			// Specify which company to use (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Set up the context object
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create a sales order object
			salesOrder = new SalesOrder();

			// Create a sales document type key for the sales order
			salesOrderType = new SalesDocumentTypeKey();
			salesOrderType.Type = SalesDocumentType.Order;

			// Populate the document type key of the sales order object
			salesOrder.DocumentTypeKey = salesOrderType;

			// Create a customer key
			customerKey = new CustomerKey();
			customerKey.Id = "AARONFIT0001";

			// Set the customer key property of the sales order object
			salesOrder.CustomerKey = customerKey;

			// Create a batch key
			batchKey = new BatchKey();
			batchKey.Id = "SALES ORDERS";

			// Set the batch key property of the sales order object
			salesOrder.BatchKey = batchKey;

			// Create a sales order line to specify the ordered item
			salesOrderLine = new SalesOrderLine();

			// Create an item key
			orderedItem = new ItemKey();
			orderedItem.Id = "32X IDE";

			// Set the item key property of the sales order line object
			salesOrderLine.ItemKey = orderedItem;

			// Create a sales order quantity object
			orderedAmount = new Quantity();
			orderedAmount.Value = 4;

			// Set the quantity of the sales order line object
			salesOrderLine.Quantity = orderedAmount;

			// Create an array of sales order lines
			// Initialize the array with sales order line object
			SalesOrderLine[] orders = { salesOrderLine };

			// Add the sales order line array to the sales order
			salesOrder.Lines = orders;

			// Get the create policy for the sales order object
			salesOrderCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesOrder", context);

			// Create the sales order
			wsDynamicsGP.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);
	}
}
}

 Native endpoint

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			SalesOrder salesOrder;
			SalesDocumentTypeKey salesOrderType;
			CustomerKey customerKey;
			BatchKey batchKey;
			SalesOrderLine salesOrderLine;
			ItemKey orderedItem;
			Quantity orderedAmount;
			Policy salesOrderCreatePolicy;

			// Create an instance of the service
			DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

			// Create a context with which to call the service
			context = new Context();

			// Specify which company to use (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Set up the context object
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create a sales order object
			salesOrder = new SalesOrder();

			// Create a sales document type key for the sales order
			salesOrderType = new SalesDocumentTypeKey();
			salesOrderType.Type = SalesDocumentType.Order;

			// Populate the document type key of the sales order object
			salesOrder.DocumentTypeKey = salesOrderType;

			// Create a customer key
			customerKey = new CustomerKey();
			customerKey.Id = "AARONFIT0001";

			// Set the customer key property of the sales order object
			salesOrder.CustomerKey = customerKey;

			// Create a batch key
			batchKey = new BatchKey();
			batchKey.Id = "SALES ORDERS";

			// Set the batch key property of the sales order object
			salesOrder.BatchKey = batchKey;

			// Create a sales order line to specify the ordered item
			salesOrderLine = new SalesOrderLine();

			// Create an item key
			orderedItem = new ItemKey();
			orderedItem.Id = "32X IDE";

			// Set the item key property of the sales order line object
			salesOrderLine.ItemKey = orderedItem;

			// Create a sales order quantity object
			orderedAmount = new Quantity();
			orderedAmount.Value = 4;

			// Set the quantity of the sales order line object
			salesOrderLine.Quantity = orderedAmount;

			// Create an array of sales order lines
			// Initialize the array with sales order line object
			SalesOrderLine[] orders = { salesOrderLine };

			// Add the sales order line array to the sales order
			salesOrder.Lines = orders;

			// Get the create policy for the sales order object
			salesOrderCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesOrder", context);

			// Create the sales order
			wsDynamicsGP.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);

			// Close the service
			if(wsDynamicsGP.State != CommunicationState.Faulted)
			{
				wsDynamicsGP.Close();
		}
	}
}
}


Documentation Feedback