CreateSalesReturn


Description

This method creates a new sales return.

Parameters

Parameter

Type

Description

salesReturn

SalesReturn

The sales return 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 return. The example first populates the required DocuemntTypeKey, CustomerKey, and BatchKey properties. The sales return uses a sales return line to specify the item and quantity returned. The sales return line requires the ItemKey, and Quantity properties to be populated. The sales return key and sales return line key are not populated. The CreateSalesReturn operation automatically populates the empty sales return key and sales return line key with the next available return number. All other sales return properties are set to default values. The CreateSalesReturn operation saves the new sales return.

 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;
			Policy salesReturnCreatePolicy;
			SalesReturn salesReturn;
			SalesDocumentTypeKey docTypeKey;
			CustomerKey customerKey;
			BatchKey batchKey;
			SalesReturnLine salesReturnLine;
			ItemKey returnedItem;
			SalesReturnQuantities salesReturnQuantity;
			Quantity returnedAmount;

			// 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 return object
			salesReturn = new SalesReturn();

			// Create a sales document type key
			docTypeKey = new SalesDocumentTypeKey();
			docTypeKey.Type = SalesDocumentType.Return;

			// Set the document type key of the sales return object
			salesReturn.DocumentTypeKey = docTypeKey;

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

			// Set the customer key property of the sales return object
			salesReturn.CustomerKey = customerKey;

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

			// Set the batch key property of the sales return object
			salesReturn.BatchKey = batchKey;

			// Create a sales return line to specify the returned item
			salesReturnLine = new SalesReturnLine();

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

			// Set the item key property of the sales return line object
			salesReturnLine.ItemKey = returnedItem;

			// Create a sales return quantity object
			salesReturnQuantity = new SalesReturnQuantities();

			// Create a quantity object
			returnedAmount = new Quantity();
			returnedAmount.Value = 1;

			// Set the returned quantity property of the sales return quantities object 
			salesReturnQuantity.ReturnedQuantity = returnedAmount;

			// Set the returned quantity property of the sales return line object
			salesReturnLine.ReturnQuantity = salesReturnQuantity;

			// Set the quantity property of the sales return line object
			salesReturnLine.Quantity = returnedAmount;

			// Create an array of sales return lines
			// Initialize the array with the sales return line object
			SalesReturnLine[] returns = { salesReturnLine };

			// Add the sales return line array to the sales return object
			salesReturn.Lines = returns;

			// Get the create policy for sales returns
			salesReturnCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesReturn", context);

			// Create the sales return
			wsDynamicsGP.CreateSalesReturn(salesReturn, context, salesReturnCreatePolicy);
	}
}
}

 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;
			Policy salesReturnCreatePolicy;
			SalesReturn salesReturn;
			SalesDocumentTypeKey docTypeKey;
			CustomerKey customerKey;
			BatchKey batchKey;
			SalesReturnLine salesReturnLine;
			ItemKey returnedItem;
			SalesReturnQuantities salesReturnQuantity;
			Quantity returnedAmount;

			// 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 return object
			salesReturn = new SalesReturn();

			// Create a sales document type key
			docTypeKey = new SalesDocumentTypeKey();
			docTypeKey.Type = SalesDocumentType.Return;

			// Set the document type key of the sales return object
			salesReturn.DocumentTypeKey = docTypeKey;

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

			// Set the customer key property of the sales return object
			salesReturn.CustomerKey = customerKey;

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

			// Set the batch key property of the sales return object
			salesReturn.BatchKey = batchKey;

			// Create a sales return line to specify the returned item
			salesReturnLine = new SalesReturnLine();

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

			// Set the item key property of the sales return line object
			salesReturnLine.ItemKey = returnedItem;

			// Create a sales return quantity object
			salesReturnQuantity = new SalesReturnQuantities();

			// Create a quantity object
			returnedAmount = new Quantity();
			returnedAmount.Value = 1;

			// Set the returned quantity property of the sales return quantities object 
			salesReturnQuantity.ReturnedQuantity = returnedAmount;

			// Set the returned quantity property of the sales return line object
			salesReturnLine.ReturnQuantity = salesReturnQuantity;

			// Set the quantity property of the sales return line object
			salesReturnLine.Quantity = returnedAmount;

			// Create an array of sales return lines
			// Initialize the array with the sales return line object
			SalesReturnLine[] returns = { salesReturnLine };

			// Add the sales return line array to the sales return object
			salesReturn.Lines = returns;

			// Get the create policy for sales returns
			salesReturnCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesReturn", context);

			// Create the sales return
			wsDynamicsGP.CreateSalesReturn(salesReturn, context, salesReturnCreatePolicy);

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


Documentation Feedback