{"id":1329,"date":"2020-02-02T16:02:39","date_gmt":"2020-02-02T16:02:39","guid":{"rendered":"https:\/\/ricardomoinhos.com\/?p=1329"},"modified":"2020-02-02T16:02:48","modified_gmt":"2020-02-02T16:02:48","slug":"bind-subscription-in-dynamics-nav-business-central","status":"publish","type":"post","link":"https:\/\/ricardomoinhos.com\/pt\/bind-subscription-in-dynamics-nav-business-central\/","title":{"rendered":"Bind Subscription in Dynamics NAV \/ Business Central"},"content":{"rendered":"\n<p>BINDSUBSCRIPTION is a function in Dynamics NAV and Business Central that is not very well know (yet) but it is very handy on several situations.<\/p>\n\n\n\n<p>If you&#8217;re already embracing the beautiful (and challenging) world of events then you&#8217;ll surely use the BINDSUBSCRIPTION function.<\/p>\n\n\n\n<p>In this article I will present you with 3 usage examples. None of them are real business cases and a few coding best practices were ignored for sake of simplicity.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Usage Examples<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Example 1 &#8211; Activate subscribers on demand<\/h3>\n\n\n\n<p>I have a specific process where I want to print an invoice but I want to use a different report than the report configured in reports selection. Please note that I want to &#8220;replace&#8221; the report only when this process is being executed.<\/p>\n\n\n\n<p>To do the replacement you can subscribe the OnAfterSubstituteReport event published in codeunit  ReportManagement. For more info, please check this url: <a href=\"https:\/\/robertostefanettinavblog.com\/2020\/01\/23\/substituting-reports\/\">https:\/\/robertostefanettinavblog.com\/2020\/01\/23\/substituting-reports\/<\/a> (thanks Roberto Stefanetti).<\/p>\n\n\n\n<p>So, you&#8217;re already using events, right? Then you know that when you subscribe an event, the subscriber is called by the publisher every time, right? Well, sort of&#8230; There&#8217;s a property called <strong>EventSubscriberInstance<\/strong> (<a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics-nav\/eventsubscriberinstance-property\">https:\/\/docs.microsoft.com\/en-us\/dynamics-nav\/eventsubscriberinstance-property<\/a>) that allows you to indicate if the subscribers should be bound to events automatically or manually. To bound subscribers to events manually the property must be set to <strong>Manual<\/strong>.<\/p>\n\n\n\n<p>I&#8217;ve created a new codeunit for the purpose of replacing the report to be used, that subscribes event <strong>OnAfterSubstituteReport<\/strong> in codeunit <strong>ReportManagement<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50101 \"Substitute The Report\"<br>&nbsp;{<br>&nbsp;EventSubscriberInstance = Manual;<br>&nbsp;\u200b<br>&nbsp; &nbsp;  [EventSubscriber(ObjectType::Codeunit, Codeunit::\"ReportManagement\", 'OnAfterSubstituteReport', '', true, true)]<br>&nbsp; &nbsp;  local procedure \"ReportManagement_OnAfterSubstituteReport\"(ReportId: Integer; RunMode: Option; RequestPageXml: Text; RecordRef: RecordRef; var NewReportId: Integer)<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp;      IF ReportId = REPORT::\"Sales - Invoice\" THEN<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  NewReportId := REPORT::\"Standard Sales - Invoice\";<br>&nbsp; &nbsp;  end;<br>&nbsp;}<\/pre>\n\n\n\n<p>Please note that the property <strong>EventSubscriberInstance<\/strong> is set to <strong>Manual<\/strong> so these subscribers won&#8217;t be called unless they&#8217;re activated. To activate the subscribers I must bind the subscription.<\/p>\n\n\n\n<p>I&#8217;ve created two codeunits to show two different behaviors. I believe the codeunit name is self explanatory.<\/p>\n\n\n\n<p><strong>Codeunit -&gt; Will Print Original Report<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50102 \"Will Print Original Report\"<br>&nbsp;{<br>&nbsp; &nbsp;  trigger OnRun()<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  SalesInvoiceHeader: Record \"Sales Invoice Header\";<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  SalesInvoiceHeader.FindFirst();<br>&nbsp; &nbsp; &nbsp; &nbsp;  REPORT.RunModal(REPORT::\"Sales - Invoice\", true, true, SalesInvoiceHeader);<br>&nbsp; &nbsp;  end;<br>&nbsp;}<\/pre>\n\n\n\n<p><strong>Codeunit -&gt; Print the Substitute Report<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50103 \"Print the Substitute Report\"<br>&nbsp;{<br>&nbsp; &nbsp;  trigger OnRun()<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  SalesInvoiceHeader: Record \"Sales Invoice Header\";<br>&nbsp; &nbsp; &nbsp; &nbsp;  SubstituteTheReport: Codeunit \"Substitute The Report\";<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  SalesInvoiceHeader.FindFirst();<br>&nbsp; &nbsp; &nbsp; &nbsp;  BindSubscription(SubstituteTheReport);<br>&nbsp; &nbsp; &nbsp; &nbsp;  REPORT.RunModal(REPORT::\"Sales - Invoice\", true, true, SalesInvoiceHeader);<br>&nbsp; &nbsp; &nbsp; &nbsp;  UnbindSubscription(SubstituteTheReport);  \/\/ Not necessary because when SubstituteTheReport codeunit goes out of scope, all bindings are removed.<br>&nbsp; &nbsp;  end;<br>&nbsp;}<\/pre>\n\n\n\n<p>I&#8217;ve extended the Customer List page to add two actions to test the codeunits:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;pageextension 50101 \"CustomerListExt\" extends \"Customer List\"<br>&nbsp;{<br>&nbsp; &nbsp;  actions<br>&nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp;  addlast(Creation)<br>&nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  group(MyActionGroup)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Action(MyAction1)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ApplicationArea = All;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Caption = 'Print Report - No Bind';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  RunObject = codeunit \"Will Print Original Report\";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Promoted = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedIsBig = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedCategory = Process;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Action(MyAction2)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ApplicationArea = All;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Caption = 'Print Report - Bind';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  RunObject = codeunit \"Will Print Substituted Report\";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Promoted = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedIsBig = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedCategory = Process;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp;  }<br>&nbsp;}<\/pre>\n\n\n\n<p>Here&#8217;s the output when I run codeunit <strong>Will Print Original Report<\/strong>. <strong>&#8220;Sales &#8211; Invoice&#8221;<\/strong> report is printed.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"554\" src=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_1.png\" alt=\"\" class=\"wp-image-1336\" srcset=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_1.png 750w, https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_1-300x222.png 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>But if I run codeunit <strong>Will Print Substituted Report<\/strong>, then <strong>&#8220;Standard Sales &#8211; Invoice&#8221;<\/strong> report is printed instead because the subscribers in codeunit are bound.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"421\" src=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_2.png\" alt=\"\" class=\"wp-image-1337\" srcset=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_2.png 586w, https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_2-300x216.png 300w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Example 2 &#8211; Set global information in the subscribers codeunit<\/h3>\n\n\n\n<p>In this example I want to post a gen. journal and use the last entry no. later on.<\/p>\n\n\n\n<p>I&#8217;ve created the following objects to demonstrate this.<\/p>\n\n\n\n<p>Codeunit <strong>Example 2 &#8211; Aux Methods<\/strong> -&gt; The codeunit is used to create and post a gen. journal line.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50107 \"Example 2 - Aux Methods\"<br>&nbsp;{<br>&nbsp; &nbsp;  procedure CreateAndPostGenJnlLine()<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine: Record \"Gen. Journal Line\";<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJnlPostBatch: Codeunit \"Gen. Jnl.-Post Batch\";<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  \/\/ For demo purposes only - Values hardcoded.<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.INIT;<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.SetHideValidation(TRUE);<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Source Code\", 'GENJNL');<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Journal Template Name\", 'GENERAL');<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Journal Batch Name\", 'DEFAULT');<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Line No.\", 10000);<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Account Type\", GenJournalLine.\"Account Type\"::\"G\/L Account\");<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Document No.\", '.');<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Account No.\", '2910');<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Document Date\", WorkDate());<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Posting Date\", WorkDate());<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(Amount, 100);<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Bal. Account Type\", GenJournalLine.\"Bal. Account Type\"::\"G\/L Account\");<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Bal. Account No.\", '2910');<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Bal. Gen. Posting Type\", GenJournalLine.\"Bal. Gen. Posting Type\"::\" \");<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Bal. Gen. Bus. Posting Group\", '');<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Bal. Gen. Prod. Posting Group\", '');<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Bal. VAT Prod. Posting Group\", '');<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.VALIDATE(\"Bal. VAT Bus. Posting Group\", '');<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJournalLine.INSERT(TRUE);<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;  GenJnlPostBatch.Run(GenJournalLine);<br>&nbsp; &nbsp;  end;<br>&nbsp;\u200b<br>&nbsp;}<\/pre>\n\n\n\n<p>Codeunit <strong>Storage<\/strong> -&gt; Created to subscribe the <strong>OnAfterGLFinishPosting<\/strong> event and save the Last Entry No. in variable global <strong>PostedEntryNo<\/strong>.<\/p>\n\n\n\n<p>Please note the the <strong>EventSubscriberInstance<\/strong> property is set to <strong>Manual<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50106 \"Storage\"<br>&nbsp;{<br>&nbsp; &nbsp;  EventSubscriberInstance = Manual;<br>&nbsp;\u200b<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  PostedEntryNo: Integer;<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  procedure GetPostedEntryNo(): Integer<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  exit(PostedEntryNo);<br>&nbsp; &nbsp;  end;<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  [EventSubscriber(ObjectType::Codeunit, Codeunit::\"Gen. Jnl.-Post Line\", 'OnAfterGLFinishPosting', '', true, true)]<br>&nbsp; &nbsp;  local procedure \"Gen. Jnl.-Post Line_OnAfterGLFinishPosting\"(GLEntry: Record \"G\/L Entry\"; var GenJnlLine: Record \"Gen. Journal Line\"; IsTransactionConsistent: Boolean; FirstTransactionNo: Integer; var GLRegister: Record \"G\/L Register\"; var TempGLEntryBuf: Record \"G\/L Entry\"; var NextEntryNo: Integer; var NextTransactionNo: Integer)<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  PostedEntryNo := NextEntryNo;<br>&nbsp; &nbsp;  end;<br>&nbsp;\u200b<br>&nbsp;}<\/pre>\n\n\n\n<p>Codeunit <strong>Example 2 &#8211; No Bind<\/strong>. This is the codeunit that will be executed to show the first scenario. I didn&#8217;t use the <strong>BINDSUBSCRIPTION<\/strong> so the saved value in variable <strong>PostedEntryNo<\/strong>, in codeunit <strong>Storage<\/strong>, is lost and not retrieved when <strong>GetPostedEntryNo<\/strong> method is called.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50104 \"Example 2 - No Bind\"<br>&nbsp;{<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  Storage: Codeunit \"Storage\";<br>&nbsp; &nbsp; &nbsp; &nbsp;  Aux: Codeunit \"Example 2 - Aux Methods\";<br>&nbsp;\u200b<br>&nbsp; &nbsp;  trigger OnRun()<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  Aux.CreateAndPostGenJnlLine();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;  \/\/ Do additional processing...<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;  MESSAGE(Format(Storage.GetPostedEntryNo()));<br>&nbsp; &nbsp;  end;<br>&nbsp;\u200b<br>&nbsp;}<\/pre>\n\n\n\n<p>Codeunit <strong>Example 2 &#8211; Bind<\/strong> -&gt; This is the codeunit that will be executed to show the second scenario. This time I used the <strong>BINDSUBSCRIPTION<\/strong> so the saved value in variable <strong>PostedEntryNo<\/strong>, in codeunit <strong>Storage<\/strong>, is not lost and is correctly retrieved when <strong>GetPostedEntryNo<\/strong> method is called.<\/p>\n\n\n\n<p>When <strong>BINDSUBSCRIPTION<\/strong> is used, you control the lifespan of the subscriber codeunit so the instance is stored and the content is not cleared and can be accessed until the codeunit subscription is unbound.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50105 \"Example 2 - Bind\"<br>&nbsp;{<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  Storage: Codeunit \"Storage\";<br>&nbsp; &nbsp; &nbsp; &nbsp;  Aux: Codeunit \"Example 2 - Aux Methods\";<br>&nbsp;\u200b<br>&nbsp; &nbsp;  trigger OnRun()<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  BindSubscription(Storage);<br>&nbsp; &nbsp; &nbsp; &nbsp;  Aux.CreateAndPostGenJnlLine();<br>&nbsp; &nbsp; &nbsp; &nbsp;  MESSAGE(Format(Storage.GetPostedEntryNo()));<br>&nbsp; &nbsp; &nbsp; &nbsp;  UnbindSubscription(Storage);<br>&nbsp; &nbsp;  end;<br>&nbsp;\u200b<br>&nbsp;}<\/pre>\n\n\n\n<p>Once again, I&#8217;ve extended the Customer List page to add two actions to test the codeunits:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;pageextension 50102 \"CustomerListExt\" extends \"Customer List\"<br>&nbsp;{<br>&nbsp; &nbsp;  actions<br>&nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp;  addlast(Creation)<br>&nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  group(MyActionGroup)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Action(MyAction1)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ApplicationArea = All;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Caption = 'Post Gen. Jnl. Line - No Bind';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  RunObject = codeunit \"Example 2 - No Bind\";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Promoted = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedIsBig = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedCategory = Process;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Action(MyAction2)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ApplicationArea = All;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Caption = 'Post Gen. Jnl. Line - Bind';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  RunObject = codeunit \"Example 2 - Bind\";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Promoted = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedIsBig = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedCategory = Process;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp;  }<br>&nbsp;\u200b<br>&nbsp;}<\/pre>\n\n\n\n<p>When I press the <strong>Post Gen. Jnl. Line &#8211; No Bind<\/strong> action, the codeunit <strong>Example 2 &#8211; No Bind<\/strong> is executed and the following message is retrieved because the posted G\/L Entry No. stored in variable <strong>PostedEntryNo<\/strong> was lost:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"199\" src=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_3.png\" alt=\"\" class=\"wp-image-1332\" srcset=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_3.png 626w, https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_3-300x95.png 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/a><\/figure>\n\n\n\n<p>But if I press the <strong>Post Gen. Jnl. Line &#8211; Bind<\/strong> action, the codeunit <strong>Example 2 &#8211; Bind<\/strong> is executed and the entry no. is correctly retrieved from the <strong>PostedEntryNo<\/strong> variable because the codeunit was bound and the instance is stored until the codeunit is unbound.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"625\" height=\"201\" src=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_4.png\" alt=\"\" class=\"wp-image-1333\" srcset=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_4.png 625w, https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_4-300x96.png 300w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Example 3 &#8211; Reusing the subscriber but changing behavior<\/h3>\n\n\n\n<p>Another scenario I&#8217;ve tried was to have a subscriber that I want to be called every time. But on some specific processes I want it to have a different behavior.<\/p>\n\n\n\n<p>Imagine that you want to log in a new table the last entry no. inserted in the G\/L Entry, every time a post occurs. You can do that subscribing the <strong>OnAfterGLFinishPosting<\/strong> publisher event on codeunit <strong>Gen. Jnl.-Post Line<\/strong>. But on some specific scenarios you want the subscriber to have a different behavior. For example, showing a message to the user with the entry no. inserted in the <strong>Logging<\/strong> table.<\/p>\n\n\n\n<p>First I&#8217;ve created a new table for the log that will keep the last G\/L Entry No. inserted on each post.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;table 50100 \"Logging\"<br>&nbsp;{<br>&nbsp; &nbsp;  DataClassification = ToBeClassified;<br>&nbsp;\u200b<br>&nbsp; &nbsp;  fields<br>&nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp;  field(1; \"Entry No.\"; Integer)<br>&nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  DataClassification = ToBeClassified;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  AutoIncrement = true;<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;  field(2; \"G\/L Entry No.\"; Integer)<br>&nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  DataClassification = ToBeClassified;<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  keys<br>&nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp;  key(PK; \"Entry No.\")<br>&nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Clustered = true;<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp;  }<br>&nbsp;}<\/pre>\n\n\n\n<p>Next, I&#8217;ve created the codeunit that will subscribe <strong>OnAfterGLFinishPosting<\/strong> on codeunit <strong>Gen. Jnl.-Post Line<\/strong>. This subscriber will be called every time a gen. journal line is posted.<\/p>\n\n\n\n<p>I&#8217;ll have to do some changes in this codeunit but this would be an example of the codeunit if I just wanted to save the log.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50109 \"G\/L Logger Subscriber\"<br>&nbsp;{<br>&nbsp; &nbsp;  [EventSubscriber(ObjectType::Codeunit, Codeunit::\"Gen. Jnl.-Post Line\", 'OnAfterGLFinishPosting', '', true, true)]<br>&nbsp; &nbsp;  local procedure \"Gen. Jnl.-Post Line_OnAfterGLFinishPosting\"(GLEntry: Record \"G\/L Entry\"; var GenJnlLine: Record \"Gen. Journal Line\"; IsTransactionConsistent: Boolean; FirstTransactionNo: Integer; var GLRegister: Record \"G\/L Register\"; var TempGLEntryBuf: Record \"G\/L Entry\"; var NextEntryNo: Integer; var NextTransactionNo: Integer)<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  AddGLEntryToLog(GLEntry.\"Entry No.\");<br>&nbsp; &nbsp;  end;<br>&nbsp;\u200b<br>&nbsp; &nbsp;  procedure AddGLEntryToLog(GLEntryNo: Integer): Integer<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  Logging: Record Logging;<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  Logging.Init();<br>&nbsp; &nbsp; &nbsp; &nbsp;  Logging.\"G\/L Entry No.\" := GLEntryNo;<br>&nbsp; &nbsp; &nbsp; &nbsp;  Logging.Insert();<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;      Message('New entry added to Logging');<br>&nbsp; &nbsp;      <br>&nbsp; &nbsp; &nbsp; &nbsp;  exit(Logging.\"Entry No.\");<br>&nbsp; &nbsp;  end;<br>&nbsp;}<\/pre>\n\n\n\n<p>I will need an additional codeunit for the specific processes. In some specific processes I want to do the logging but I also want to show a message to the user with the logging entry no.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50110 \"G\/L Logger\/Message Subscriber\"<br>&nbsp;{<br>&nbsp; &nbsp;  EventSubscriberInstance = Manual;<br>&nbsp;\u200b<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  GLLogger: Codeunit \"G\/L Logger Subscriber\";<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  [EventSubscriber(ObjectType::Codeunit, Codeunit::\"Gen. Jnl.-Post Line\", 'OnAfterGLFinishPosting', '', true, true)]<br>&nbsp; &nbsp;  local procedure \"Gen. Jnl.-Post Line_OnAfterGLFinishPosting\"(GLEntry: Record \"G\/L Entry\"; var GenJnlLine: Record \"Gen. Journal Line\"; IsTransactionConsistent: Boolean; FirstTransactionNo: Integer; var GLRegister: Record \"G\/L Register\"; var TempGLEntryBuf: Record \"G\/L Entry\"; var NextEntryNo: Integer; var NextTransactionNo: Integer)<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  Message(Format(GLLogger.AddGLEntryToLog(GLEntry.\"Entry No.\")));<br>&nbsp; &nbsp;  end;<br>&nbsp;}<\/pre>\n\n\n\n<p>Please note that the <strong>EventSubscriberInstance<\/strong> property is set to <strong>Manual<\/strong>.<\/p>\n\n\n\n<p>What&#8217;s going to happen if I bind the subscription in codeunit <strong>G\/L Logger\/Message Subscriber<\/strong>? The log will occur twice because both events will be called. To avoid it I will have to make some changes in both codeunits.<\/p>\n\n\n\n<p>Codeunit <strong>G\/L Logger\/Message Subscriber<\/strong> will be changed to:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50110 \"G\/L Logger\/Message Subscriber\"<br>&nbsp;{<br>&nbsp; &nbsp;  EventSubscriberInstance = Manual;<br>&nbsp;\u200b<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  GLLogger: Codeunit \"G\/L Logger Subscriber\";<br>&nbsp; &nbsp; &nbsp; &nbsp;  IsBound: Boolean;<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  procedure SetIsBound()<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  IsBound := true;<br>&nbsp; &nbsp;  end;<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  procedure GetIsBound(): Boolean<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  exit(IsBound);<br>&nbsp; &nbsp;  end;<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  [EventSubscriber(ObjectType::Codeunit, Codeunit::\"Gen. Jnl.-Post Line\", 'OnAfterGLFinishPosting', '', true, true)]<br>&nbsp; &nbsp;  local procedure \"Gen. Jnl.-Post Line_OnAfterGLFinishPosting\"(GLEntry: Record \"G\/L Entry\"; var GenJnlLine: Record \"Gen. Journal Line\"; IsTransactionConsistent: Boolean; FirstTransactionNo: Integer; var GLRegister: Record \"G\/L Register\"; var TempGLEntryBuf: Record \"G\/L Entry\"; var NextEntryNo: Integer; var NextTransactionNo: Integer)<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  Message(Format(GLLogger.AddGLEntryToLog(GLEntry.\"Entry No.\")));<br>&nbsp; &nbsp;  end;<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  [EventSubscriber(ObjectType::Codeunit, Codeunit::\"G\/L Logger Subscriber\", 'OnCheckSubscriberIsBound', '', true, true)]<br>&nbsp; &nbsp;  local procedure IsBound_OnCheckSubscriberIsBound_GLLoggerSubscriber(var CodeunitIsBound: Boolean);<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  CodeunitIsBound := IsBound;<br>&nbsp; &nbsp;  end;<br>&nbsp;}<\/pre>\n\n\n\n<p>Codeunit <strong>G\/L Logger Subscriber<\/strong> will be changed to:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50109 \"G\/L Logger Subscriber\"<br>&nbsp;{<br>&nbsp; &nbsp;  [EventSubscriber(ObjectType::Codeunit, Codeunit::\"Gen. Jnl.-Post Line\", 'OnAfterGLFinishPosting', '', true, true)]<br>&nbsp; &nbsp;  local procedure \"Gen. Jnl.-Post Line_OnAfterGLFinishPosting\"(GLEntry: Record \"G\/L Entry\"; var GenJnlLine: Record \"Gen. Journal Line\"; IsTransactionConsistent: Boolean; FirstTransactionNo: Integer; var GLRegister: Record \"G\/L Register\"; var TempGLEntryBuf: Record \"G\/L Entry\"; var NextEntryNo: Integer; var NextTransactionNo: Integer)<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  IsBound: Boolean;<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  OnCheckSubscriberIsBound(IsBound);<br>&nbsp; &nbsp; &nbsp; &nbsp;  if IsBound then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  exit;<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp; &nbsp;  AddGLEntryToLog(GLEntry.\"Entry No.\");<br>&nbsp; &nbsp;  end;<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  procedure AddGLEntryToLog(GLEntryNo: Integer): Integer<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  Logging: Record Logging;<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  Logging.Init();<br>&nbsp; &nbsp; &nbsp; &nbsp;  Logging.\"G\/L Entry No.\" := GLEntryNo;<br>&nbsp; &nbsp; &nbsp; &nbsp;  Logging.Insert();<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;      Message('New entry added to Logging');<br>&nbsp; &nbsp;      <br>&nbsp; &nbsp; &nbsp; &nbsp;  exit(Logging.\"Entry No.\");<br>&nbsp; &nbsp;  end;<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  [IntegrationEvent(false, false)]<br>&nbsp; &nbsp;  local procedure OnCheckSubscriberIsBound(var CodeunitIsBound: Boolean)<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;  end;<br>&nbsp;}<\/pre>\n\n\n\n<p>I&#8217;ve created two codeunits to simulate the behavior on both situations.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50112 \"Example 3 - No Bind\"<br>&nbsp;{<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  Aux: Codeunit \"Example 3 - Aux Methods\";<br>&nbsp;\u200b<br>&nbsp; &nbsp;  trigger OnRun()<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  Aux.CreateAndPostGenJnlLine();<br>&nbsp; &nbsp;  end;<br>&nbsp;}<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;codeunit 50113 \"Example 3 - Bind\"<br>&nbsp;{<br>&nbsp; &nbsp;  var<br>&nbsp; &nbsp; &nbsp; &nbsp;  Aux: Codeunit \"Example 3 - Aux Methods\";<br>&nbsp; &nbsp; &nbsp; &nbsp;  LoggerMessage: Codeunit \"G\/L Logger\/Message Subscriber\";<br>&nbsp;\u200b<br>&nbsp; &nbsp;  trigger OnRun()<br>&nbsp; &nbsp;  begin<br>&nbsp; &nbsp; &nbsp; &nbsp;  BindSubscription(LoggerMessage);<br>&nbsp; &nbsp; &nbsp; &nbsp;  Aux.CreateAndPostGenJnlLine();<br>&nbsp; &nbsp; &nbsp; &nbsp;  UnbindSubscription(LoggerMessage);<br>&nbsp; &nbsp;  end;<br>&nbsp;}<\/pre>\n\n\n\n<p>I\u2019ve extended the Customer List page to add two actions to test the codeunits:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;pageextension 50102 \"CustomerListExt\" extends \"Customer List\"<br>&nbsp;{<br>&nbsp; &nbsp;  actions<br>&nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp;  addlast(Creation)<br>&nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  group(MyActionGroup)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Action(MyAction1)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ApplicationArea = All;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Caption = 'Post Gen. Jnl. Line - No Bind';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  RunObject = codeunit \"Example 3 - No Bind\";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Promoted = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedIsBig = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedCategory = Process;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp;\u200b<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Action(MyAction2)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ApplicationArea = All;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Caption = 'Post Gen. Jnl. Line - Bind';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  RunObject = codeunit \"Example 3 - Bind\";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Promoted = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedIsBig = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PromotedCategory = Process;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp; &nbsp; &nbsp;  }<br>&nbsp; &nbsp;  }<br>&nbsp;}<\/pre>\n\n\n\n<p>When I press the <strong>Post Gen. Jnl. Line &#8211; No Bind<\/strong> action, the codeunit <strong>Example 3 &#8211; No Bind<\/strong> is executed and the following message is retrieved:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"196\" src=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_5.png\" alt=\"\" class=\"wp-image-1334\" srcset=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_5.png 626w, https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_5-300x94.png 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<p>A new record is added to <strong>Logging<\/strong> table but that&#8217;s it.<\/p>\n\n\n\n<p>If I press the <strong>Post Gen. Jnl. Line &#8211; Bind<\/strong> action, the codeunit <strong>Example 3 &#8211; Bind<\/strong> is executed and the following messages are retrieved:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"196\" src=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_5.png\" alt=\"\" class=\"wp-image-1334\" srcset=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_5.png 626w, https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_5-300x94.png 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"625\" height=\"198\" src=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_6.png\" alt=\"\" class=\"wp-image-1335\" srcset=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_6.png 625w, https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/BINDSUBSCRIPTION_Image_6-300x95.png 300w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/figure>\n\n\n\n<p>A new record is added to the <strong>Logging<\/strong> table and a message is shown with the inserted logging entry no..<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>I hope you enjoyed this article and found it useful.<\/p>\n\n\n\n<p>Please feel free to comment on this.<\/p>\n\n\n\n<p>Source code available in Github: <a href=\"https:\/\/github.com\/ricardopaiva\/NAVBC_bindsubscription_example\">https:\/\/github.com\/ricardopaiva\/NAVBC_bindsubscription_example<\/a><\/p>\n\n\n\n<p>Source: <a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics-nav\/bindsubscription-function\">https:\/\/docs.microsoft.com\/en-us\/dynamics-nav\/bindsubscription-function<\/a><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>BINDSUBSCRIPTION is a function in Dynamics NAV and Business Central that is not very well know (yet) but it is very handy on several situations. If you&#8217;re already embracing the beautiful (and challenging) world of events then you&#8217;ll surely use the BINDSUBSCRIPTION function. In this article I will present you with 3 usage examples. None [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1358,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[4],"tags":[59,6],"class_list":{"0":"post-1329","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-dynamics365bc","8":"tag-businesscentral","9":"tag-dynamicsnav-2","11":"post-with-thumbnail","12":"post-with-thumbnail-icon"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Bind Subscription in Dynamics NAV \/ Business Central - Ricardo Paiva Moinhos<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bind Subscription in Dynamics NAV \/ Business Central - Ricardo Paiva Moinhos\" \/>\n<meta property=\"og:description\" content=\"BINDSUBSCRIPTION is a function in Dynamics NAV and Business Central that is not very well know (yet) but it is very handy on several situations. If you&#8217;re already embracing the beautiful (and challenging) world of events then you&#8217;ll surely use the BINDSUBSCRIPTION function. In this article I will present you with 3 usage examples. None [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/\" \/>\n<meta property=\"og:site_name\" content=\"Ricardo Paiva Moinhos\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-02T16:02:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-02-02T16:02:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/Microsoft-Dynamics-365-Business-Central-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"256\" \/>\n\t<meta property=\"og:image:height\" content=\"256\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ricardo Paiva Moinhos\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ricardo Paiva Moinhos\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/\"},\"author\":{\"name\":\"Ricardo Paiva Moinhos\",\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/#\\\/schema\\\/person\\\/16dcfdd54ec1c46bd1941659739de4cc\"},\"headline\":\"Bind Subscription in Dynamics NAV \\\/ Business Central\",\"datePublished\":\"2020-02-02T16:02:39+00:00\",\"dateModified\":\"2020-02-02T16:02:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/\"},\"wordCount\":1105,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ricardomoinhos.com\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Microsoft-Dynamics-365-Business-Central-Logo.png\",\"keywords\":[\"\",\"dynamicsnav\"],\"articleSection\":[\"Dynamics NAV\\\/365 BC\"],\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/\",\"url\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/\",\"name\":\"Bind Subscription in Dynamics NAV \\\/ Business Central - Ricardo Paiva Moinhos\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ricardomoinhos.com\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Microsoft-Dynamics-365-Business-Central-Logo.png\",\"datePublished\":\"2020-02-02T16:02:39+00:00\",\"dateModified\":\"2020-02-02T16:02:48+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/#\\\/schema\\\/person\\\/16dcfdd54ec1c46bd1941659739de4cc\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/#primaryimage\",\"url\":\"https:\\\/\\\/ricardomoinhos.com\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Microsoft-Dynamics-365-Business-Central-Logo.png\",\"contentUrl\":\"https:\\\/\\\/ricardomoinhos.com\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Microsoft-Dynamics-365-Business-Central-Logo.png\",\"width\":256,\"height\":256},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/bind-subscription-in-dynamics-nav-business-central\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ricardomoinhos.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bind Subscription in Dynamics NAV \\\/ Business Central\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/#website\",\"url\":\"https:\\\/\\\/ricardomoinhos.com\\\/\",\"name\":\"Ricardo Paiva Moinhos\",\"description\":\"Welcome\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ricardomoinhos.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ricardomoinhos.com\\\/#\\\/schema\\\/person\\\/16dcfdd54ec1c46bd1941659739de4cc\",\"name\":\"Ricardo Paiva Moinhos\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/248366f4e615e182964f85f799c6e33cbd541a6f4ca7ee948fc16d1c14030c76?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/248366f4e615e182964f85f799c6e33cbd541a6f4ca7ee948fc16d1c14030c76?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/248366f4e615e182964f85f799c6e33cbd541a6f4ca7ee948fc16d1c14030c76?s=96&d=mm&r=g\",\"caption\":\"Ricardo Paiva Moinhos\"},\"url\":\"https:\\\/\\\/ricardomoinhos.com\\\/pt\\\/author\\\/ricardopaiva\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bind Subscription in Dynamics NAV \/ Business Central - Ricardo Paiva Moinhos","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/","og_locale":"pt_PT","og_type":"article","og_title":"Bind Subscription in Dynamics NAV \/ Business Central - Ricardo Paiva Moinhos","og_description":"BINDSUBSCRIPTION is a function in Dynamics NAV and Business Central that is not very well know (yet) but it is very handy on several situations. If you&#8217;re already embracing the beautiful (and challenging) world of events then you&#8217;ll surely use the BINDSUBSCRIPTION function. In this article I will present you with 3 usage examples. None [&hellip;]","og_url":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/","og_site_name":"Ricardo Paiva Moinhos","article_published_time":"2020-02-02T16:02:39+00:00","article_modified_time":"2020-02-02T16:02:48+00:00","og_image":[{"width":256,"height":256,"url":"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/Microsoft-Dynamics-365-Business-Central-Logo.png","type":"image\/png"}],"author":"Ricardo Paiva Moinhos","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Ricardo Paiva Moinhos","Tempo estimado de leitura":"17 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/#article","isPartOf":{"@id":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/"},"author":{"name":"Ricardo Paiva Moinhos","@id":"https:\/\/ricardomoinhos.com\/#\/schema\/person\/16dcfdd54ec1c46bd1941659739de4cc"},"headline":"Bind Subscription in Dynamics NAV \/ Business Central","datePublished":"2020-02-02T16:02:39+00:00","dateModified":"2020-02-02T16:02:48+00:00","mainEntityOfPage":{"@id":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/"},"wordCount":1105,"commentCount":0,"image":{"@id":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/#primaryimage"},"thumbnailUrl":"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/Microsoft-Dynamics-365-Business-Central-Logo.png","keywords":["","dynamicsnav"],"articleSection":["Dynamics NAV\/365 BC"],"inLanguage":"pt-PT","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/","url":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/","name":"Bind Subscription in Dynamics NAV \/ Business Central - Ricardo Paiva Moinhos","isPartOf":{"@id":"https:\/\/ricardomoinhos.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/#primaryimage"},"image":{"@id":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/#primaryimage"},"thumbnailUrl":"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/Microsoft-Dynamics-365-Business-Central-Logo.png","datePublished":"2020-02-02T16:02:39+00:00","dateModified":"2020-02-02T16:02:48+00:00","author":{"@id":"https:\/\/ricardomoinhos.com\/#\/schema\/person\/16dcfdd54ec1c46bd1941659739de4cc"},"breadcrumb":{"@id":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/"]}]},{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/#primaryimage","url":"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/Microsoft-Dynamics-365-Business-Central-Logo.png","contentUrl":"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/Microsoft-Dynamics-365-Business-Central-Logo.png","width":256,"height":256},{"@type":"BreadcrumbList","@id":"https:\/\/ricardomoinhos.com\/bind-subscription-in-dynamics-nav-business-central\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ricardomoinhos.com\/"},{"@type":"ListItem","position":2,"name":"Bind Subscription in Dynamics NAV \/ Business Central"}]},{"@type":"WebSite","@id":"https:\/\/ricardomoinhos.com\/#website","url":"https:\/\/ricardomoinhos.com\/","name":"Ricardo Paiva Moinhos","description":"Welcome","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ricardomoinhos.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/ricardomoinhos.com\/#\/schema\/person\/16dcfdd54ec1c46bd1941659739de4cc","name":"Ricardo Paiva Moinhos","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/secure.gravatar.com\/avatar\/248366f4e615e182964f85f799c6e33cbd541a6f4ca7ee948fc16d1c14030c76?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/248366f4e615e182964f85f799c6e33cbd541a6f4ca7ee948fc16d1c14030c76?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/248366f4e615e182964f85f799c6e33cbd541a6f4ca7ee948fc16d1c14030c76?s=96&d=mm&r=g","caption":"Ricardo Paiva Moinhos"},"url":"https:\/\/ricardomoinhos.com\/pt\/author\/ricardopaiva\/"}]}},"jetpack_featured_media_url":"https:\/\/ricardomoinhos.com\/wp-content\/uploads\/2020\/02\/Microsoft-Dynamics-365-Business-Central-Logo.png","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/posts\/1329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/comments?post=1329"}],"version-history":[{"count":13,"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/posts\/1329\/revisions"}],"predecessor-version":[{"id":1357,"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/posts\/1329\/revisions\/1357"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/media\/1358"}],"wp:attachment":[{"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/media?parent=1329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/categories?post=1329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ricardomoinhos.com\/pt\/wp-json\/wp\/v2\/tags?post=1329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}