CreateSalesItem


Description

This method creates a new sales item.

Parameters

Parameter

Type

Description

salesItem

SalesItem

The sales item 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 item. The example populates the required Key, Description, and UofMScheduleKey properties. All other sales item properties are set to default values. The CreateSalesItem operation saves the new sales item.

 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;
			ItemKey itemKey;
			UofMScheduleKey unitOfMeasureKey;
			SalesItem salesItem;
			Policy salesItemCreatePolicy;

			// 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 item object
			salesItem = new SalesItem();

			// Create a sales item key object to identify the sales item
			itemKey = new ItemKey();
			itemKey.Id = "TESTINVENTORYITEM0005";

			// Populate the sales item key property
			salesItem.Key = itemKey;

			// Populate the description property
			salesItem.Description = "Test inventory item 05";

			// Create a unit of measure schedule key
			unitOfMeasureKey = new UofMScheduleKey();
			unitOfMeasureKey.Id = "EACH";

			// Populate the unit of measure property
			salesItem.UofMScheduleKey = unitOfMeasureKey;

			// Get the create policy for sales item
			salesItemCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesItem", context);

			// Create the sales item
			wsDynamicsGP.CreateSalesItem(salesItem, context, salesItemCreatePolicy);
	}
}
}

 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;
			ItemKey itemKey;
			UofMScheduleKey unitOfMeasureKey;
			SalesItem salesItem;
			Policy salesItemCreatePolicy;

			// 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 item object
			salesItem = new SalesItem();

			// Create a sales item key object to identify the sales item
			itemKey = new ItemKey();
			itemKey.Id = "TESTINVENTORYITEM0005";

			// Populate the sales item key property
			salesItem.Key = itemKey;

			// Populate the description property
			salesItem.Description = "Test inventory item 05";

			// Create a unit of measure schedule key
			unitOfMeasureKey = new UofMScheduleKey();
			unitOfMeasureKey.Id = "EACH";

			// Populate the unit of measure property
			salesItem.UofMScheduleKey = unitOfMeasureKey;

			// Get the create policy for sales item
			salesItemCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesItem", context);

			// Create the sales item
			wsDynamicsGP.CreateSalesItem(salesItem, context, salesItemCreatePolicy);

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


Documentation Feedback