So, NAV TechDays 2014 have started, again, with the pre-conference sessions that were all sold out and packed full.
Today I had an extraordinary pleasure to teach the advanced .NET Interoperability concepts to 15 people that came from all over the world, from Brazil to Australia. It was an interesting workshop, challenging – I must say (thanks to Rafael who made me improvise a solution to a typical DotNet limitation), and I am looking forward to delivering two more sessions about .NET and Control Add-ins tomorrow, and on Friday.
As promised, I am making the materials from the presentation available for the download, in case you want to learn the same stuff the attendees learned today.
To check if a BLOB field has a value, you call its HASVALUE function. For example: IF Item.Picture.HASVALUE THEN;
In older versions, earlier than NAV 2009, you had to call CALCFIELDS before you could check HASVALUE, which – if you think of it, did not make much sense. This was changed in NAV 2009, so ever since that version you can check HASVALUE before you decide to call CALCFIELDS first. It makes all the sense – you don’t need to pull up to 2GB of data over just to see if anything is inside.
If you are an old-school guy (or just old, as me), and you CALCFIELDS first, HASVALUE next, maybe it’s time for you to reconsider it.
Rembember – the pattern is: IF Field.HASVALUE THEN Rec.CALCFIELDS(Field);
Any function that accepts only one parameter can be called as if it were a property, and this applies to built-in system functions, your own custom functions, and even .NET methods alike. Instead of doing it like Report50001.SetDefaultPostingDate(101015D) you can always do it like Report50001.SetDefaultPostingDate := 101015D. Of course you can improve semantics of your code significantly if you simply call the function PostingDate instead of SetDefaultPostingDate, then you can just write Report50001.PostingDate := 101015D;
Remember – this works for all function types, even .NET method calls.
While it may be a cold day in hell before we see any TRY..CATCH constructs in pure C/AL, we are all far more lucky when it comes to .NET interoperability. In this blog post I’ll (re)present the same concept I demonstrated during NAV TechDays 2013 last year in Antwerp, because I am quite sure this nifty little trick got lost under piles of other posts on this blog.
So, let’s learn how to do try..catch..finally for .NET interoperability C/AL code, using mostly C/AL code.