Extensions 2.0 - How can I prevent OnValidate-Trigger in OnBeforeValidate?

elbartuselbartus Member Posts: 2
edited 2018-05-29 in NAV Three Tier
Hello,

just writing a little extensions for Dynamics NAV 2018.
And therefore I got the following question in that example:

I modify Name on Vendor-Table like

modify (Name)
{

trigger OnBeforeValidate();
begin
IF CONFIRM('Do you want to prevent/skip OnValidate?') THEN
// ????????? <- is there something I can call to prevent/skip the OnValidate-Trigger (Expect of ERROR or TESTFIELD)?
end;

}

I've already tried to call EXIT there, but that just leaves the OnBeforeValidate-Trigger an does not prevent OnValidate.

Do you have an idea?

Thanks

El Bartus

Best Answer

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Answer ✓
    You can't. That's the 'beauty' of Extensions - you can only add to existing code.

    On the other hand - what's wrong with stopping update by throwing ERROR in OnBeforeValidate in this case?

    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Answer ✓
    You can't. That's the 'beauty' of Extensions - you can only add to existing code.

    On the other hand - what's wrong with stopping update by throwing ERROR in OnBeforeValidate in this case?

    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • elbartuselbartus Member Posts: 2
    Hello Slawek,

    In fact, it's nothing wrong to throw an ERROR. But that way, you are not able to change the behaviour of the Validation. Here: Search Name is set to Name.

    But thanks, that helped me a lot!
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    You can workaround it to some extent by creating two subscribers, one to OnBeforeValidate event and one to OnAfterValidate, both in one codeunit, set the EventSubscriberInstance property on that codeunit to Manual, and bind both subscribers manually (for example creating another subscriber subscribing to OnAfterCompanyOpen from Cu1, in another codeunit with default EventSubscriberInstance setting, handling automatic binding).

    Manually bound subscribes (unlike the static-automatic ones) can preserve the object vars between calls, so you could remember the old Name in some global var in OnBeforeValidate, and put it back in OnAfterValidate in all required places - coding restoring the value in all required places manually of course, without using the Validate trigger on the field to avoid loops.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • krikikriki Member, Moderator Posts: 9,112
    [Topic moved from 'Navision Financials' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.