waldo’s blog

Microsoft Dynamics NAV

NAV2013: How to link a factbox in code

Before you think I give you the Oracle with this article … this is actually nothing but showing you a new feature in NAV2013.

New?

Not really .. but that’s how Microsoft tells it :-). It wasn’t there in NAV2009 RTC .. so it must be new, right? Well, not really .. because we already had this in the classic for years .. but it wasn’t “ported” to the RTC in NAV2009.

OnAfterGetCurrRecord is BACK!

I hear you thinkin’ .. Oh yeah!

A few weeks ago, I actually needed this in a NAV2013 project. I needed a “programmable” linked factbox, which contained records with a generic link, using RecordID. Let’s say something like the table “Record Links”. Suppose you’ve got a table like that, and want a factbox on any page to show the linked records of your table.

In a nutshell: I want a programmable linked factbox.

And that’s fairly easy. It’s just a matter of creating a function in your factbox that is going to take care of the filtering. Call this function “OnAfterGetCurrRecord” and that’s about it:

Step 1: Create a factbox with a function to update your records

Like you see below, I created a new factbox on the “Record Link” table with two fields and the function which is going to take care of the filtering, based on the record ID. Not the “CurrPage.UPDATE”, which is going to be necessary to refresh your factbox after filtering..

Step 2: Use your factbox, and call the function OnAfterGetCurrRecord:

To be able to call a function on your factbox, you’ll have to name your factbox in (in my case) the Customer List page.. As you can see, I named it “RecLinkFactbox”.

The code for your filtering can be as complex as you want it to be .. but of course .. keep “performance” in the back of your mind.

Speaking of which

One of the things we (as developers) always have to manage when doing these kind of things, are things like: “what if I don’t show my factbox .. is it still going to call that function and do the filtering in the background?”. Of course it does! And you SHOULD manage that .. and we actually can do that quite easily.

But that’s for the next blogpost … :-)

If you want to read up on the OnAfterGetCurrRecord trigger .. here is a good place to start: http://msdn.microsoft.com/en-us/library/dd301413(v=nav.70).aspx


 


 


 


 


 

January 7th, 2013 Posted by waldo | Dynamics NAV | no comments

No Comments »

No comments yet.

Leave a comment

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word