Cache enabled display field not refreshing issue in Operations
Scenario: I have created a display method which is a calculated field called "grossweight". This simply adds two fields net weight+tara weight. Added this display method to form grid. Whenever i change value in grossweight or gross weight, display field should be updated accordingly. This works fine when you have not enabled cache on the display field. Cache is enabled in order to improve the performance of the form.
Issue here is when we enable cache our display method stopped refreshing with the new values. In my case when changing netweight value grossweight display field was not updated. This is a standard behaviour but from a user perspective this is not acceptable.
Solution:
On modified of fields gross weight and net weight call cacheCalculateMethod. This will recalculate the display field value hence requirement is achieved. Also performance is not affected as we call the methods only in modified of the two fields.
Code sample:
[FormDataFieldEventHandler(formDataFieldStr(WHSPhysDimUOMPerVariant, WHSPhysDimUOMPerVariant, TaraWeight), FormDataFieldEventType::Modified)]
public static void TaraWeight_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
FormDataSource formDataSource = sender.datasource();
formDataSource.cacheCalculateMethod(#GrossWeight);
}
[FormDataFieldEventHandler(formDataFieldStr(WHSPhysDimUOMPerVariant, WHSPhysDimUOMPerVariant, NetWeight), FormDataFieldEventType::Modified)]
public static void NetWeight_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
FormDataSource formDataSource = sender.datasource();
formDataSource.cacheCalculateMethod(#GrossWeight);
}
Please note that we need to pass method display method name as parameter. In the example grossweight is the display method name.
Comments
Post a Comment