D365 Business Central Extending Deferrals

dborg
dborg Member Posts: 3
Hi All,

I am trying to extended the functionality of Deferrals (Sales Lines table, onValidate of deferral code).

Automatically, when validating deferral code, NAV is creating the Deferral Schedule (in the below screenshot calling "DeferralCodeOnValidate").

217iux4id2d2.png

In short, I need to update the global variable "DeferralPostDate" before calling the function "DeferralCodeOnValidate" by using some information from the SalesLine record.

There is an event raised "OnGetDeferralPostDate" which I thought would be brilliant, to subscribe to it, update the "DeferralPostDate" and all my troubles will be solved. The thing is, that from my subscriber function, I will not have visibility to the Sales Line record (Rec) which i need for my logic. I cannot subscribe to the OnValidate event (raised by the platform) since I will not have access to the global variable "DeferralPostDate" and unfortunately the raised event "OnGetDeferralPostData" does not give access to global variables.

Obviously I cannot update any base code, as that's the whole point of BC on cloud.

I feel that i'm stuck between a rock and a hard place :smile: Any tips (or comments to correct me) will be greatly appreciated.

Good day ladies and gents
Dave


Comments

  • Andrewalwin69
    Andrewalwin69 Member Posts: 12

    You’re hitting a normal BC limitation. that event doesn’t give enough context (no Sales Line), and you can’t access the global variable.

    Best approach:

    • Set your logic before deferral runs. use Sales Line events like OnValidate of Deferral Code
    • Pre-calculate what you need, then let standard logic continue
    • If needed, store values in a custom field on Sales Line and use that

    You can’t safely change it inside DeferralCodeOnValidate, so prepare the data earlier instead