Skip to main content

In my process, I need to update two InfoPath forms at the completion of each step of the process (custom status flags).  There is some bit of logic involved here that I absolutely hate to duplicate in each step, and I would love to make a common method that accepts parameters and performs the update, so I could just call this method in every step passing the appropriate parameters.  Is there a way to make process level methods, accessible by 'server code' events?


The only way I can see it right now is to create a seperate class lilbrary project with this method and add a reference to this library in the K2 project.  I cannot add my own classes to the K2 project, at least not by obvious means.

I just tried something and it worked.  Hopefully the same will work for you.  I put a Default Server Event in the first Activity of a process.  I went into the code and put the following method:


        public static string Test(string input)
        {
            return input + "world";
        }


The class name for this Server Event is EventItem_6312392b46a84bc4b5a23e1cffce1494.  I then added another Server Event in another Activity and put the following code:


            using(StreamWriter sw = new StreamWriter(@"C: empoutput.txt", false))
            {
                sw.Write(EventItem_6312392b46a84bc4b5a23e1cffce1494.Test("hello, "));
            }


I ran the process and had a file called output.txt with hello, world in it.  I would think that you should be able to go into any of your non-Default Server Event code files and use this approach. 


One more note...  The Server Event is going to place the .cs files in the CSCode-xxxx project.  You should be able to use the same approach by adding the static method to your non-DefaultServerEvent events to the code-behind so it is referencable from the CSWinWF-xxxx project files.


Why don't you create a seperate project (assembly) that you references in both your K2 processes?

Cato,


A seperate assembly is my current solution but it seemed like overkill for just one simple method.  I was hoping I was mising an easier way, to keep things as simple as possible.  I'm afraid erice's solution, while technically sound is a bit too complicated (no offense, erice, I appreciate the idea).


Putting in a separate assembly is the recommended way to do it.


Reply