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

   

   

   

   

   

Posted: 2013-1-7 12:02 by waldo | with 6 comment(s) |
Bookmark and Share

Comments

# re: NAV2013: How to link a factbox in code

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.

Tuesday, January 15, 2013 9:02 AM by Erik Albrodt

# re: NAV2013: How to link a factbox in code

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

Tuesday, January 15, 2013 9:04 AM by waldo

# re: NAV2013: How to link a factbox in code

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 ;-)

Friday, February 08, 2013 3:49 PM by Sebi64

# re: NAV2013: How to link a factbox in code

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.  

Friday, February 08, 2013 4:26 PM by waldo

# re: NAV2013: How to link a factbox in code

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

Thursday, March 14, 2013 9:12 AM by Christine

# re: NAV2013: How to link a factbox in code

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.. .

Thursday, March 14, 2013 9:21 AM by waldo

Leave a Comment

(required) 
(required) 
(optional)
(required)