OOO, C#, and C/AL

I’ve been working with building some web services built on the Microsoft Dynamics Nav 2009 web services platform. Microsoft is doing something fairly slick here - you write code in the C/AL language, save it as a Nav Object, expose it as a web service, and the web services layer automatically translates the C/AL to C# and runs it in .Net. This allows you to debug the code using visual studio, among other things.

But it’s not perfect. Sometimes it makes mistakes.

I had this line of code in C/AL

1
IF AVSetup.”Sub Award Dimension No.” - 1 IN [1..8] THEN BEGIN

Which auto-translated to this in C#:

if(aVSetup.Target.GetFieldValueSafe(90, NavType.Integer)
  .ToInt32()-(1 >= 1 && 1

Oops. The order of operations got mixed up. The C/AL code subtracts one, then sees if the value is between 1 and 8. The C# sees if 1 is between 1 and 8 (getting a boolean value) and then tries to subtract the boolean value from the number. C# then gives this error:

Operator ‘-‘ cannot be applied to operands of type ‘int’ and ‘bool’

Thankfully, the solution for this is simple. All you have to do is use extra parentheses to explicitly set the Order of Operations.

1
IF ((AVSetup.”Sub Award Dimension No.” - 1) IN [1..8]) THEN BEGIN

SQL Reporting Services, Sharepoint, and Firefox

I ran into a problem when I tried to use Firefox to view a SQL report on Sharepoint. In IE it works fine, but when it hits firefox, a ‘display: block-inline’ CSS style set on a table buried way down in the code caused firefox to do this:


The report is squeezed into a little IFrame, and you don’t even get a vertical scrollbar. Sure, you can right-click on it and get your browser to show that IFrame as the main page, but that’s not a good solution for end users. So I set about trying to figure out how to take care of this.

I found all kinds of helpful information about the problem. Lots of people had solutions, but none of them worked for me. Here is some of what I found:

Read More

Sharepoint Thumbnails and AssetUploader.aspx

We recently had a consultant build a web part for us that displayed thumbnails from images in a document library. In digging around in the code they gave us I discovered that they used a page built into Sharepoint called AssetUploader.aspx (in 12\TEMPLATE\LAYOUTS\AssetUploader.aspx, available off any web at _layouts\AssetUploader.aspx). This page is a rather handy. It’s specifically designed to take a URL of an available image, resize it, and spit out a thumbnail. You can use it in any page or web part in Sharepoint by creating an IMG tag like this:

1
<img src=”http://www.blogger.com/_layouts/AssetUploader.aspx?Size=Medium&ImageURL=/mysitecollection/mysite/MyImagesDocumentLibrary/IMG1234.jpgalt=”My Image” />

If you use a size of ‘Small’, it will make the largest dimension of the image 70 pixels, and if you use anything other than small (Medium, Large, etc.), it will make the largest dimension of the image 140 pixels.
It worked wonderfully in our test environment, but once we brought it into production, it broke. All we saw were little generic white document icons - no thumbnails. Yikes!

Read More

NAV Automation Object

I took me a good while, but I finally managed to get my first automation object created, compiled, and made visible in NAV. Stefano Demiliani provided most of the guidance that I needed on this, as well as a few postings on mibuso, but there were a few other tricks I picked up on in the process that I figured I’d share here. Also, since I couldn’t find one anywhere else, I figured I’d post a complete Visual Studio sample project.

You can download the sample project at http://bitsofinsanity.blob.core.windows.net/public/NavAutomation.zip

Please note that I am far from an expert on COM objects - I figured out just enough to get my code to compile and work, but it’s highly likely that my work is suboptimal, so if anyone has any ideas for improvement, please share them.

I suppose I should explain what I’m talking about. Microsoft Dynamics NAV is an ERP system that contains and manages our Finances, Accounting, HR, Events, and more. It has tables of data (backed by SQL Server), forms to display the data, reports, and more. Each of these object types can have code behind it controlling what it does. However, the extensibility is limited to using COM objects, which are called ‘Automation Objects’ in NAV. But so long as you can create a COM object properly, you can insert it into a table or form and, through that COM object, you can do whatever the .Net framework allows you to do.

Read More