K2 4.5 Tip of the Day - First inline function/Where the heck is my icon?

I have been having some fun creating a custom inline function and it was somewhat easy to create a new function without much hassle.

Now I am not going to go through the entire documented process as per the Excel Services Inline Function (I would recommend you read the word document in the project site first).

In a nutshell:

  1. Create a new .NET C# class project in VS2008. 
  2. Select .NET Framework 3.5 as the target.
  3. Once done, add the necessary references (refer to the doc for the dll locations in the GAC and K2 folders)
    1. SourceCode.Framework
    2. SourceCode.Workflow.Functions
    3. SourceCode.Workflow.Functions.Design
    4. System.Drawing
  4. Put in the necessary using statements and you are all set to begin creating your first inline function!

For my own first inline function, I wanted to create a function that provided the ability to access a particular item in a list array (Out of the box functions allow you to Count, GetFirstItem and GetLastItem).

Here's a code snippet of this function.

Now note that you cannot add your custom function to the default inline function categories (I know.  I tried it).  After checking with the inline function lab dude, basically this is because the original category is registered to the official K2 functions class (you can't register the same class in the same namespace).  So the best workaround I had was to append a "2" after my class (i.e. Functions2).

I wrote my function and tested it out.  It worked right out of the box and it was surprisingly easy to create.  One little note is that I had to close Visual Studio, deploy the dll and then start Visual Studio to get the function to show up (refresing didn't work for me).

However, one little thing.... for some reason, my icon didn't show up.  :(

Note this particular line of code:

This was a standard line in all the examples on k2underground and I couldn't figure out why my icon didn't show (it just showed a generic gear icon).  I tried embedding the png file into the resource (from looking at one of the other samples).  I tried compiling the assembly with and without the png extension and it all didn't work.  I was totally stumped and it was driving me crazy.

At this point, labs to the rescue!  I sent up my code to the inline functions lab dude and he helped me determine where my mistake was.

So just a couple of key notes from the guru.

1) Make sure your namespace is set correctly.  The namespace of my class was "SourceCode.Workflow", you have to make sure that your project properties is set to the same. In my case mine was set to "Workflow" because my solution name was "SourceCode" and the project was "Workflow".

2) Make sure that the png is compiled as an embedded resource.  Note that you do not need to add the png file to the resource file (resx) contrary to what some of the samples on blackmarket show.

 Once I did these two things, closed VS2008, deployed my dlls, open VS2008 and my icon finally shows!

So I guess apart from some "programmer" issues here, I did got my first inline function working successfully 100%!

I hope some of these tips will help other budding inline function coders who have difficulty getting the icon portion working.  Cheers!

P.S. I'll share out my inline function project later on blackmarket once I do a bit more work on it.


Posted Tue, May 11 2010 8:06 PM by johnny