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

   

   

   

   

   

  • Anonymous
    Anonymous

    Yes, it works, but the page crashes, if a user makes the factbox invisible. ;)

    You can't check the visibility of a factbox via code. So the function tries to send the Update-Command to a control that not even exists.

  • You actually can check the visibility in code .. just need to put that into a blogpost :-/

  • Anonymous
    Anonymous

    Hello,

    I'm wondering how you do know that the factbox is displayed or not?

    Currently I haven't found a way to do it.

    Please, give me just a hint ;-)

  • Right .. I was going to put that on my blog.

    It will be there soon .. but be aware, I will be posting this on www.waldo.be.  

  • Anonymous
    Anonymous

    Hi Waldo

    Thanks for your very clear item. I work with 2009 R2 and I tried out the link to the factbox.

    The problem is that the factbox is displayed, but with the first record, not the linked record.

    The function works fine if I open the factbox page (just the page, not as a factbox, with a call to the function on "open page") and the call to the function from the main page works (I verified with assigning a return value to the function). So I guess the UPDATE does not work properly. Does anybody have a suggestion?

    Thanks!

    Christine

  • Hi Christine,

    you're lucky that I've seen this comment, because I moved my blog to www.Waldo.Be :-).

    note that this blog is about NAV2013, and the fact that OnAfterGetCurrRecord is back.  We didn't have OnAfterGetCurrRecord in NAV2009, which is essential to link your factbox in code .. .  So I guess that's where your problem is.. .