Tips and Tricks for creating Inline Functions
Here are a few tips for creating Inline Functions:
- A good way to see if the resources specified in the attributes are pointing to the correct location, is by using intellisense, i.e. see if you can access MyInlineFunction.Properties.Resources from code.
- This is with the exception of the image icon which should be compiled as an embedded resource and is therefore referenced in the K2Icon attribute using the folder structure as the namespace.
- Classes and methods should be public and static.
- Remember to copy your dll into both the K2\Bin\Functions folder and HostServer\Bin.
- Any single class can only contain functions of a single category because the category is determined at the class level.
- If you aren’t planning on adding functions to the out-of-box categories, there’s no need to reference SourceCode.Workflow.Functions or SourceCode.Workflow.Functions.Design.
- Runtime can be debugged in the regular manner of attaching the project to HostServer.
- Try sticking to .Net primitive types for inputs and returns or validation on the UI can get tricky and you might have to create some extra conversion functions, etc.
- Passing in or returning lists of primitives are done with arrays.
- Using the System.Object type for an input parameter causes the type validation step to be skipped on the UI and you can pass in anything. If you do this, keep type safety in mind and handle type conversion errors gracefully in your code
- Using object as a return type will require the user to either select a primitive type from the return type dropdown or to wrap the function in a conversion function with an expected return type.
- If you are considering creating a function with an input of type object, keep type safety in mind, but also remember that the UI won’t prevent users from passing in lists instead of single items.
- There isn’t an out-of-the-box way of converting an object returned from a function to an array.
- Try not to change the namespace of the Microsoft Visual Studio solution for the Inline Function. Locating all the associated namespace properties is difficult and if one is missed out and not changed to match the new name the
Inline Function will not show in the K2 designer. Visual Studio will also not report an error if you change the namespace.
- We recommend that all custom inline functions should be created in a separate category. In some versions of K2, an exception can occur if you add a custom function to a built-in Category.
Troubleshooting Icon Display
If you are using a custom icon and it is not displaying correctly, the following tips may help solve the issue:
-
The default namespace as specified in the project properties should be the same as the namespace of the type.
-
The image file should be marked as Embedded in its Build Action.