Retrieving action tracking information
To retrieve action tracking information, use the "GetChanged" methods in the Dynamics GP service. These methods take a criteria object that specifies the time period and other properties that specify the actions to examine. They return collections of "changed key" objects that represent the actions that occurred.
Warning: Entity action tracking must be enabled for the "GetChanged" web methods to return valid results.
Restriction criteria
To specify the actions you want to retrieve, you must create a "ChangedKeyCriteria" object. This object specifies the time range and other properties that indicate what actions you want to examine. For example, the following C# code shows how the criteria object is created to retrieve the actions performed on sales orders over the last week.
** Legacy endpoint**
SalesOrderChangedKeyCriteria salesOrderCriteria; BetweenRestrictionOfNullableOfDateTime restriction; // Create the restriction that defines the interval examined for actions // 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 sales order objects that were acted on salesOrderCriteria = new SalesOrderChangedKeyCriteria(); salesOrderCriteria.LastModifiedDate = restriction;
** Native endpoint **
SalesOrderChangedKeyCriteria salesOrderCriteria; BetweenRestrictionOfNullableOfdateTime restriction; // Create the restriction that defines the interval examined for actions // 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 sales order objects that were acted on salesOrderCriteria = new SalesOrderChangedKeyCriteria(); salesOrderCriteria.LastModifiedDate = restriction;
Restricting by action
By default, all of the create, update, and delete actions for the specified time period will be returned. You can use the "data modification action" restriction to return actions of a specific type. For example, the following C# code shows how to create the criteria so that only the create actions for salesperson objects performed in the last day are returned.
** Legacy endpoint**
SalespersonChangedKeyCriteria salespersonCriteria; BetweenRestrictionOfNullableOfDateTime restriction; RestrictionOfNullableOfDataModificationAction dataModificationRestriction; // Create the restriction that defines the interval examined for actions // The following restriction includes all of today restriction = new BetweenRestrictionOfNullableOfDateTime(); restriction.From = DateTime.Today.Date; restriction.To = DateTime.Today.Date.AddDays(1); // Create the restriction so only created salespeople are returned dataModificationRestriction = new RestrictionOfNullableOfDataModificationAction(); dataModificationRestriction.EqualValue = DataModificationAction.Created; // Create the criteria to return salesperson objects that were created salespersonCriteria = new SalespersonChangedKeyCriteria(); salespersonCriteria.LastModifiedDate = restriction; salespersonCriteria.Action = dataModificationRestriction;
** Native endpoint **
SalespersonChangedKeyCriteria salespersonCriteria; BetweenRestrictionOfNullableOfdateTime restriction; RestrictionOfNullableOfDataModificationAction dataModificationRestriction; // Create the restriction that defines the interval examined for actions // The following restriction includes all of today restriction = new BetweenRestrictionOfNullableOfdateTime(); restriction.From = DateTime.Today.Date; restriction.To = DateTime.Today.Date.AddDays(1); // Create the restriction so only created salespeople are returned dataModificationRestriction = new RestrictionOfNullableOfDataModificationAction(); dataModificationRestriction.EqualValue = DataModificationAction.Created; // Create the criteria to return salesperson objects that were created salespersonCriteria = new SalespersonChangedKeyCriteria(); salespersonCriteria.LastModifiedDate = restriction; salespersonCriteria.Action = dataModificationRestriction;
You will use the collection of the "changed key" objects returned by the "GetChanged" web method as the basis for further processing. Each "changed key" object contains the key value for the object for which the action was performed. You can use the key values to retrieve the full object if needed.