Skip to main content

When we are trying to write custom code for K2 worflow, where should we start with? Is it the K2 Studio or we need to write the code in Visual Studio and deploy it?

You may want to post more about what exactly you're trying to do as maybe custom code is not required.  K2 is flexible so that are often multiple approaches that can be taken to solve a problem.

 

With that said the quick answer is adding custom code to a process requires Visual Studio.  You can't add custom code in K2 Studio.


Thank you for the reply.

 

My requirement has workflow step to move the document to a new library once its approved. I need to alert the user if a document with the same name is already present in the destination. The alert should be triggered in the first step of the workflow.


Hi TV,

 

I'm just about positive you can do all of this (and more) in K2 without writing a single line of code.  I'm making this example in the K2 designer for sharepoint as it seemed to be the quickest and easiest way to get started with a sharepoint integrated workflow.

 

I created 2 libraries to try this:

 

14315i4B74917EC856B7D7.png

 

Then I generated a smartobject for TestLib2, and then generated both a smartobject and a workflow for TestLib1.  I set it to automatically start the workflow when an item is added to the list.  I didn't grab screenshots, but this is fairly straightforward.

 

Then I went and grabbed the "Move Document by ID" Wizard from the "TestLib1" Smartobject

12706iFDB4A58B1365B6F2.png

 

Filled in the stuff....

 

10771i592A774990794592.png

 

That last field "Overwrite existing documents" will be very interesting in a moment.  But for right this second, we now have a workflow that will move stuff from one library to another.

 

You'll also note that you can configure it to return values (IE.  select do not overwrite, see if a value gets returned, if value gets returned we are good, if not, prompt to rename the file and try again perhaps?)

11490iAC71977CE46ADCFC.png

 

Just to try something, I went ahead and checked "No" on "Overwrite existing Docs", and then I uploaded the same document again to the first library, which should cause some strife and anguish when it tries to move it to the second library


16475iDFDC3F8D36CF7579.png

 

So there's an exception thrown that can be caught and dealt with whenever that happens.

 

I'd also like to mention that you could avoid the need for renaming (if business rules allow), by adding say, any sort of date/time/username stamp to the filename when you move the file around.

 

 You could also do a prelimenary check on TestLib2 in a preceeding step to see if the filename is going to be an issue, and then respond accordingly, which is another no code solution.

 

So there's a ton of different approaches that might work for you in creating this, and quite a few don't require any coding at all.

 

Good luck with your project!

 

Regards,

 

Mike


Reply