CU 1 - OnDatabase methods

nboettchernboettcher Member Posts: 14
edited 2014-08-22 in NAV Three Tier
I have placed a call to my own code unit within the OnDatabaseInsert, OnDatabaseModify and OnDatabaseDelete methods in CU 1.
However, I have found these methods are only being called if I have the Change Log turned on for the particular table.

1. Is there a way to modify to make those methods always get fired?
2. Where is the code that calls those methods?
3. Is there a way to create my own "global" on database change methods in CU1 that will fire for any change?

Comments

  • whitaker_timwhitaker_tim Member Posts: 23
    These triggers are fire automatically from the page by NAV behind the scenes so we do not have control over these functions. Although these functions are fired for pages they are not fired when changes are made via code logic (i.e. Processing reports, etc). I do not know of a way to create global functions but we can use these functions and piggyback on the logic as does the InteractionManagement in NAV 2013. What version are you currently using and can you give a little detail around what it is you are trying to accomplish, there may be another method to approach the challenge.
    Tim Whitaker | Senior NAV Consultant/Developer | The Software Workshop Ltd. | http://www.thesoftwareworkshop.com
  • deV.chdeV.ch Member Posts: 543
    whitaker_tim: that's not true for OnDatabase Triggers, it was like this in the old OnGlobal Triggers (only called by user interactions) but now with the new triggers, they are fired on every database change!

    Here is more info about it:
    http://www.dynamics.is/?p=869
    http://msdn.microsoft.com/en-us/library/gg502491.aspx

    BTW: Whyt you need to to is, you need your own TriggerMask Logic, see the Integration Mgt. how they did it. The OnDatabase Triggers are fired based on these TriggerMasks that is requested in the GetDatabaseTableTriggerSetup() Function (CU1).
  • whitaker_timwhitaker_tim Member Posts: 23
    Thank you for the clarification of details, it is certainly helpful that these now fire no matter whether code or user interaction.
    Tim Whitaker | Senior NAV Consultant/Developer | The Software Workshop Ltd. | http://www.thesoftwareworkshop.com
  • Big_DBig_D Member Posts: 207
    Hi Guys

    This routine works great in 2009
    RecordChangeLog()
    TableBasePtr (DATABASE::"Payment Terms", 4, 1, 1, 'CLS', lxRecRef);
    lPayTerms.GET ('CLS');
    lPayTerms."Discount %" := 6;
    lPayTerms.MODIFY;
    TableBasePtr (DATABASE::"Payment Terms", 4, 1, 1, 'CLS', lRecRef);
    lChangLogMgt.OnGlobalModify (lRecRef, lxRecRef);
    lRecRef.CLOSE;
    lxRecRef.CLOSE;
    
    TableBasePtr(pTableNo : Integer;pFieldNo : Integer;pKeyIndex : Integer;pKeyField : Integer;pPrimaryField : Code[10];VAR pRecRef : Recor
    pRecRef.OPEN (pTableNo);
    IF pRecRef.WRITEPERMISSION () = FALSE THEN
      ERROR ('Can write to %1', pRecRef.NAME);
    lKeyRef := pRecRef.KEYINDEX (pKeyIndex);
    lFieldRef := lKeyRef.FIELDINDEX (pKeyField);
    lFieldRef.SETRANGE (pPrimaryField);
    IF pRecRef.FIND ('-') THEN
      BEGIN
        lFieldRef := pRecRef.FIELD (pFieldNo);
        IF lFieldRef.ACTIVE = FALSE THEN
          ERROR ('Could not Activate Field %1 in Table No. %2', pFieldNo, pTableNo);
      END;
    

    But has anybody created the same senario in NAV 2013R2, where you wish to record Change Log Entries for records changes in Code? The following didn't work...
    RecordChangeLog()
    lPayTerms.GET ('CLS');
    lPayTerms."Discount %" := 11;
    lPayTerms.MODIFY;
    TableBasePtr (DATABASE::"Payment Terms", 4, 1, 1, 'CLS', lRecRef);
    lChangLogMgt.OnDatabaseModify (lRecRef);
    lRecRef.CLOSE;
    PAGE.RUN (PAGE::"Change Log Entries");
    
    TableBasePtr(pTableNo : Integer;pFieldNo : Integer;pKeyIndex : Integer;pKeyField : Integer;pPrimaryField : Code[10];VAR pRecRef : RecordRef)
    pRecRef.OPEN (pTableNo);
    IF pRecRef.WRITEPERMISSION () = FALSE THEN
      ERROR ('Can write to %1', pRecRef.NAME);
    lKeyRef := pRecRef.KEYINDEX (pKeyIndex);
    lFieldRef := lKeyRef.FIELDINDEX (pKeyField);
    lFieldRef.SETRANGE (pPrimaryField);
    IF pRecRef.FIND ('-') THEN
      BEGIN
        lFieldRef := pRecRef.FIELD (pFieldNo);
        IF lFieldRef.ACTIVE = FALSE THEN
          ERROR ('Could not Activate Field %1 in Table No. %2', pFieldNo, pTableNo);
      END;
    

    With thanks
    Big D signing off!
  • mgnmgn Member Posts: 39
    Just did some tests with 2016 and the OnDataBaseDelete trigger.
    It seems that it only works if the ChangeLog is enabled.
    (and service tier has to be restarted after setting changelog)
  • BeliasBelias Member Posts: 2,998
    deV.ch wrote: »
    whitaker_tim: that's not true for OnDatabase Triggers, it was like this in the old OnGlobal Triggers (only called by user interactions) but now with the new triggers, they are fired on every database change!

    Here is more info about it:
    http://www.dynamics.is/?p=869
    http://msdn.microsoft.com/en-us/library/gg502491.aspx

    BTW: Whyt you need to to is, you need your own TriggerMask Logic, see the Integration Mgt. how they did it. The OnDatabase Triggers are fired based on these TriggerMasks that is requested in the GetDatabaseTableTriggerSetup() Function (CU1).

    Cool stuff, thanks for sharing (and thanks to the author). I think i stayed away from mibuso for too long :(
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.