MoneyPercentChoice


Description

A value that is either a money amount or a percent amount.

Properties

Property

Type

Length

Default

Description

Item

Choice

N/A

N/A

A choice type that contains either a MoneyAmount or a Percent amount.


Examples

The following C# example demonstrates how to retrieve the Item property of a money percent choice object and determine whether it is a money amount or a percent amount. In this example, the value is the FinanceCharge property for a customer object. Note how the GetType() function is used to retrieve the underlying type of the Item property, and how the typeof() function is used to retrieve the types for the comparison operation.

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

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			Customer customer;
			CustomerKey customerKey;
			MoneyPercentChoice financeCharge;
			MoneyAmount financeChargeAmount;
			Percent financeChargePercent;

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

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

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

			// Specify which company (lesson company)
			companyKey = new DynamicsGPService.CompanyKey();
			companyKey.Id = (-1);

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

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

			// Retrieve the customer object
			customer = wsDynamicsGP.GetCustomerByKey(customerKey, context);

			// Examine the finance charge information
			financeCharge = new MoneyPercentChoice();
			financeCharge = customer.FinanceCharge;

			if (financeCharge.Item.GetType() == typeof(MoneyAmount))
			{
				financeChargeAmount = (MoneyAmount)financeCharge.Item;
				MessageBox.Show("Finance charge is a money amount of: " 
				+ financeChargeAmount.Value.ToString());
		}

			if (financeCharge.Item.GetType() == typeof(Percent))
			{
				financeChargePercent = (Percent)financeCharge.Item;
				MessageBox.Show("Finance charge is a percentage: " + financeChargePercent.Value.ToString());
		}
	}
}
}

The following C# example shows how the Item property for a customer finance charge can be set to a money amount, in this case $10 USD. Notice how the Item property is cast to be of the proper type.

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

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			Customer customer;
			CustomerKey customerKey;
			MoneyPercentChoice financeCharge;
			MoneyAmount financeChargeAmount;
			Policy customerUpdatePolicy;

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

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

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

			// Specify which company (lesson company)
			companyKey = new DynamicsGPService.CompanyKey();
			companyKey.Id = (-1);

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

			// Get the UpdateCustomer policy
			customerUpdatePolicy = wsDynamicsGP.GetPolicyByOperation("UpdateCustomer", context);

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

			// Create the customer object
			customer = new Customer();
			customer.Key = customerKey;

			// Set the finance charge information
			financeCharge = new MoneyPercentChoice();
			financeChargeAmount = new MoneyAmount();
			financeChargeAmount.Value = 10M;
			financeChargeAmount.DecimalDigits = 2;
			financeChargeAmount.Currency = "USD";
			financeCharge.Item = (MoneyAmount)financeChargeAmount;
			customer.FinanceCharge = financeCharge;

			// Update the customer
			wsDynamicsGP.UpdateCustomer(customer, context, customerUpdatePolicy);
	}
}
}


Documentation Feedback