Requirement is to enable the change tracking on table which is not part of the entity at all. But that table is being used in postLoad() to populate the values in an entity.
Let’s take an example of WMSLocation entity, we have added a custom column in that table and poplulating that column in postLoad method of the entity from some other table (demoLocationType). Now the scenario is when we are updating or adding data in this custom table then system should push or update data in wmsLocation entity.
If we are enabling primary or All table change tracking on entity, system won't update the WMSLocation when we are updating or adding column in table 'demoLocationType'.
Solution - We should write a custom method and name that 'defaultCTQuery' and in that method we would have create a query based on the relation between above two tables WMSLocation and demoLocationType and return the query object.
public static Query defaultCTQuery()
{
Query q;
q = new Query();
QueryBuildDataSource qbd = q.addDataSource(tablename2id('WMSLocation'));
qbd = qbd.addDataSource(tablename2id('demoLocationType'));
qbd.relations(false);
qbd.addLink(fieldName2Id(tableName2Id('WMSLocation'),'wMSLocationId'),fieldName2Id(tableName2Id('demoLocationType'),'wMSLocationId'));
return q;
}
And then go to Data Entities -> Filter the entity (WMSLocation) -> Change Tracking -> Enable Custom query.
Tags- #DataEntities, #ChangeTracking, #MSDYN365FO
If we are enabling primary or All table change tracking on entity, system won't update the WMSLocation when we are updating or adding column in table 'demoLocationType'.
Solution - We should write a custom method and name that 'defaultCTQuery' and in that method we would have create a query based on the relation between above two tables WMSLocation and demoLocationType and return the query object.
public static Query defaultCTQuery()
{
Query q;
q = new Query();
QueryBuildDataSource qbd = q.addDataSource(tablename2id('WMSLocation'));
qbd = qbd.addDataSource(tablename2id('demoLocationType'));
qbd.relations(false);
qbd.addLink(fieldName2Id(tableName2Id('WMSLocation'),'wMSLocationId'),fieldName2Id(tableName2Id('demoLocationType'),'wMSLocationId'));
return q;
}
And then go to Data Entities -> Filter the entity (WMSLocation) -> Change Tracking -> Enable Custom query.
Tags- #DataEntities, #ChangeTracking, #MSDYN365FO