GetChangedItemKeyList


Description

Retrieves a list of changed item key objects for the items that have been acted on during the specified interval. An item 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

ItemChangedKeyCriteria

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

context

Context

Specifies information about how the method will be called.


Return Value:

Value

Type

Description

GetChangedItemKeyListResult

ArrayOfChangedItemKey

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


Interfaces

 

Examples

The following C# example retrieves the list of the changed item key objects for all of the items that have been acted on during the previous week. The ID value of the item is used to retrieve the item object. Details about each item are displayed in the console window.

 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;
			ItemChangedKeyCriteria itemCriteria;
			ChangedItemKey[] changedItemKeyObjects;
			BetweenRestrictionOfNullableOfDateTime restriction;
			ItemKey itemKey;
			Item item;

			// 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);

			// Create the criteria to return item objects that changed
			itemCriteria = new ItemChangedKeyCriteria();
			itemCriteria.LastModifiedDate = restriction;

			// Retrieve the changed item key objects
			changedItemKeyObjects = wsDynamicsGP.GetChangedItemKeyList(itemCriteria, context);

			// Display the details about each item that acted on this week
			foreach (ChangedItemKey key in changedItemKeyObjects)
			{
				// Display the key
				Console.WriteLine("Item key: " + key.Id);

				// Display what the object knows about its changes
				Console.WriteLine("Last Modified Date: " + key.LastModifiedDate.ToString());

				// Get the item
				itemKey = new ItemKey();
				itemKey.Id = key.Id;
				item = wsDynamicsGP.GetItemByKey(itemKey, context);

				// Display the item description
				Console.WriteLine("Description: " + item.Description);

				// Display the operation performed
				if (key.Action == DataModificationAction.Created)
					Console.WriteLine("Action: Created");
				if (key.Action == DataModificationAction.Updated)
					Console.WriteLine("Action: Updated");
				if (key.Action == DataModificationAction.Deleted)
					Console.WriteLine("Action: Deleted");

				Console.WriteLine();
		}
			Console.WriteLine("Press 'Enter' to continue...");
			Console.ReadLine();
	}
}
}

 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;
			ItemChangedKeyCriteria itemCriteria;
			ChangedItemKey[] changedItemKeyObjects;
			BetweenRestrictionOfNullableOfdateTime restriction;
			ItemKey itemKey;
			Item item;

			// 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);

			// Create the criteria to return item objects that changed
			itemCriteria = new ItemChangedKeyCriteria();
			itemCriteria.LastModifiedDate = restriction;

			// Retrieve the changed item key objects
			changedItemKeyObjects = wsDynamicsGP.GetChangedItemKeyList(itemCriteria, context);

			// Display the details about each item that acted on this week
			foreach (ChangedItemKey key in changedItemKeyObjects)
			{
				// Display the key
				Console.WriteLine("Item key: " + key.Id);

				// Display what the object knows about its changes
				Console.WriteLine("Last Modified Date: " + key.LastModifiedDate.ToString());

				// Get the item
				itemKey = new ItemKey();
				itemKey.Id = key.Id;
				item = wsDynamicsGP.GetItemByKey(itemKey, context);

				// Display the item description
				Console.WriteLine("Description: " + item.Description);

				// Display the operation performed
				if (key.Action == DataModificationAction.Created)
					Console.WriteLine("Action: Created");
				if (key.Action == DataModificationAction.Updated)
					Console.WriteLine("Action: Updated");
				if (key.Action == DataModificationAction.Deleted)
					Console.WriteLine("Action: Deleted");

				Console.WriteLine();
		}
			Console.WriteLine("Press 'Enter' to continue...");
			Console.ReadLine();

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


Documentation Feedback