CreateItemCurrency


Description

This method creates a new relationship between an item and a currency.

Parameters

Parameter

Type

Description

itemCurrency

ItemCurrency

The item currency 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 an item currency relationship between an item with the key value “1-A3261A” and the currency with the ISO code “SPD“. The example uses a currency key to specify the currency and an item key to specify the item. The item currency key combines the two keys to define the relationship. All other properties use default values.

 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;
			CurrencyKey currencyKey;
			ItemKey itemKey;
			ItemCurrencyKey itemCurrencyKey;
			ItemCurrency itemCurrency;
			Policy itemCurrencyCreatePolicy;

			// 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 an item currency object
			itemCurrency = new ItemCurrency();

			// Create a currency key object
			currencyKey = new CurrencyKey();
			currencyKey.ISOCode = "SPD";

			// Create an item key object
			itemKey = new ItemKey();
			itemKey.Id = "1-A3261A";

			// Create an item currency key
			itemCurrencyKey = new ItemCurrencyKey();
			itemCurrencyKey.CurrencyKey = currencyKey;
			itemCurrencyKey.ItemKey = itemKey;

			// Populate the item currency key property with the itemCurrencyKey object
			itemCurrency.Key = itemCurrencyKey;

			// Get the create policy for item currency
			itemCurrencyCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateItemCurrency", context);

			// Create the item currency 
			wsDynamicsGP.CreateItemCurrency(itemCurrency, context, itemCurrencyCreatePolicy);
	}
}
}

 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;
			CurrencyKey currencyKey;
			ItemKey itemKey;
			ItemCurrencyKey itemCurrencyKey;
			ItemCurrency itemCurrency;
			Policy itemCurrencyCreatePolicy;

			// 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 an item currency object
			itemCurrency = new ItemCurrency();

			// Create a currency key object
			currencyKey = new CurrencyKey();
			currencyKey.ISOCode = "SPD";

			// Create an item key object
			itemKey = new ItemKey();
			itemKey.Id = "1-A3261A";

			// Create an item currency key
			itemCurrencyKey = new ItemCurrencyKey();
			itemCurrencyKey.CurrencyKey = currencyKey;
			itemCurrencyKey.ItemKey = itemKey;

			// Populate the item currency key property with the itemCurrencyKey object
			itemCurrency.Key = itemCurrencyKey;

			// Get the create policy for item currency
			itemCurrencyCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateItemCurrency", context);

			// Create the item currency 
			wsDynamicsGP.CreateItemCurrency(itemCurrency, context, itemCurrencyCreatePolicy);

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


Documentation Feedback