GetChangedCustomerAddressKeyList


Description

Retrieves a list of changed customer address key objects for the customer addresses that have been acted on during the specified interval. A customer address has been acted on if it has been created, updated, or deleted. Entity change tracking must be enabled for this method to return valid results.

Parameters

Parameter

Type

Description

criteria

CustomerAddressChangedKeyCriteria

The customer address changed key criteria object that specifies which changed customer address key objects to return.

context

Context

Specifies information about how the method will be called.


Return Value:

Value

Type

Description

GetChangedCustomerAddressKeyListResult

ArrayOfChangedCustomerAddressKey

The list of changed customer address key objects that match the specified criteria.


Interfaces

 

Examples

The following C# example retrieves the list of the changed customer address key objects that have been acted on during the last week. The list is restricted to customer AARONFIT0001. A message box displays the number of each type of address action that was performed.

 Legacy endpoint

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;
			CustomerAddressChangedKeyCriteria customerAddressCriteria;
			ChangedCustomerAddressKey[] changedCustomerAddressKeyObjects;
			BetweenRestrictionOfNullableOfDateTime restriction;
			BetweenRestrictionOfString customerRestriction;

			// 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 the restriction that defines the interval examined for changes
			// The following restriction includes the last week
			restriction = new BetweenRestrictionOfNullableOfDateTime();
			restriction.From = DateTime.Today.Date.AddDays(-7);
			restriction.To = DateTime.Today.Date.AddDays(1);

			// Restrict to just the customer AARONFIT0001
			customerRestriction = new BetweenRestrictionOfString();
			customerRestriction.EqualValue = "AARONFIT0001";

			// Create the criteria to return customer address objects that changed
			customerAddressCriteria = new CustomerAddressChangedKeyCriteria();
			customerAddressCriteria.LastModifiedDate = restriction;
			customerAddressCriteria.CustomerKeyId = customerRestriction;

			// Retrieve the changed customer address key objects
			changedCustomerAddressKeyObjects = wsDynamicsGP.GetChangedCustomerAddressKeyList(customerAddressCriteria, context);

			// Display the numbers of customer addresses that were acted on this week
			int created = 0;
			int updated = 0;
			int deleted = 0;

			foreach (ChangedCustomerAddressKey key in changedCustomerAddressKeyObjects)
			{
				if (key.Action == DataModificationAction.Created)
					created++;

				if (key.Action == DataModificationAction.Updated)
					updated++;

				if (key.Action == DataModificationAction.Deleted)
					deleted++;
		}

			string message;
			message = "Customer address changes: \n";
			message = message + "Created: " + created.ToString() + "\n";
			message = message + "Updated: " + updated.ToString() + "\n";
			message = message + "Deleted: " + deleted.ToString() + "\n";

			MessageBox.Show(message);
	}
}
}

 Native endpoint

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

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			CustomerAddressChangedKeyCriteria customerAddressCriteria;
			ChangedCustomerAddressKey[] changedCustomerAddressKeyObjects;
			BetweenRestrictionOfNullableOfdateTime restriction;
			BetweenRestrictionOfstring customerRestriction;

			// 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 the restriction that defines the interval examined for changes
			// The following restriction includes the last week
			restriction = new BetweenRestrictionOfNullableOfdateTime();
			restriction.From = DateTime.Today.Date.AddDays(-7);
			restriction.To = DateTime.Today.Date.AddDays(1);

			// Restrict to just the customer AARONFIT0001
			customerRestriction = new BetweenRestrictionOfstring();
			customerRestriction.EqualValue = "AARONFIT0001";

			// Create the criteria to return customer address objects that changed
			customerAddressCriteria = new CustomerAddressChangedKeyCriteria();
			customerAddressCriteria.LastModifiedDate = restriction;
			customerAddressCriteria.CustomerKeyId = customerRestriction;

			// Retrieve the changed customer address key objects
			changedCustomerAddressKeyObjects = wsDynamicsGP.GetChangedCustomerAddressKeyList(customerAddressCriteria, context);

			// Display the numbers of customer addresses that were acted on this week
			int created = 0;
			int updated = 0;
			int deleted = 0;

			foreach (ChangedCustomerAddressKey key in changedCustomerAddressKeyObjects)
			{
				if (key.Action == DataModificationAction.Created)
					created++;

				if (key.Action == DataModificationAction.Updated)
					updated++;

				if (key.Action == DataModificationAction.Deleted)
					deleted++;
		}

			string message;
			message = "Customer address changes: \n";
			message = message + "Created: " + created.ToString() + "\n";
			message = message + "Updated: " + updated.ToString() + "\n";
			message = message + "Deleted: " + deleted.ToString() + "\n";

			MessageBox.Show(message);

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


Documentation Feedback