Share via


MaximumWriteoff

Description

Contains information about the maximum writeoff amount for a customer or vendor.

Properties

Property

Type

Length

Default

Description

Item

Choice

N/A

N/A

A choice type that contains either a MoneyAmount or a MaximumWriteoffSpecialAmount.

Examples

The following C# example demonstrates how to retrieve the Item property of a MaximumWriteoff object and determine whether it is a money amount or a maximum writeoff special amount. 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;
            Vendor vendor;
            VendorKey vendorKey;
            MaximumWriteoff maximumWriteoff;
            MoneyAmount maximumWriteoffAmount;
            MaximumWriteoffSpecialAmount maximumWriteoffSpecialAmount;

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

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

            // Create a context object with which to call the web 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 vendor key
            vendorKey = new VendorKey();
            vendorKey.Id = "ACETRAVE0001";

            // Retrieve the vendor object
            vendor = wsDynamicsGP.GetVendorByKey(vendorKey, context);

            // Examine the maximum writeoff information
            maximumWriteoff = new MaximumWriteoff();
            maximumWriteoff = vendor.MaximumWriteoff;

            if (maximumWriteoff.Item.GetType() == typeof(MoneyAmount))
            {
                maximumWriteoffAmount = (MoneyAmount)maximumWriteoff.Item;
                MessageBox.Show("Maximum writeoff is an amount of " + maximumWriteoffAmount.Value.ToString());
            }

            if (maximumWriteoff.Item.GetType() == typeof(MaximumWriteoffSpecialAmount))
            {
                maximumWriteoffSpecialAmount = (MaximumWriteoffSpecialAmount)maximumWriteoff.Item;
                MessageBox.Show("Maximum writeoff is a special amount: " +
                maximumWriteoffSpecialAmount.ToString());
            }
        }
    }
}

The following C# example shows how the Item property for a customer maximum writeoff can be set to the value in the MaximumWriteoffSpecialAmount enumeration. 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;
            MaximumWriteoff maximumWriteoff;
            Policy customerUpdatePolicy;

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

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

            // Create a context object with which to call the web 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;

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

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

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

            // Set the maximum writeoff information
            maximumWriteoff = new MaximumWriteoff();
            maximumWriteoff.Item = (MaximumWriteoffSpecialAmount)MaximumWriteoffSpecialAmount.NotAllowed;
            customer.MaximumWriteoff = maximumWriteoff;

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