Skip to main content

HI all,

 

Got a question regarding whether or not it is recommend to change the auto generated code in K2 workflow events.

 

For example: i drag an email event onto visual studio workflow. I right click on the event and click "View Code". This shows me what code is being executed by the email event i just dragged on to the canvas. Now i can see several methods, the one I want to change is the SendMail_Execute(object sender, EventArgs e).

 

Now all i want to put here is a simple if condition around the code of this method to check the value of a datafield and depending on that either execute the code to send the email or not. Now, If I do this, will there be problem in the future. Has anyone experienced problems when doing something similar. If seems easier and visually cleaner to do this than to create a seperate activity and line rules. Especially since this occurs a lot in this process I am making.

 

Thanks

Hi,


 


It is not recommended to edit the code that you can view from the workflows within Visual Studio. While it is possible to edit the code there and have it be isolated just to that workflow, what I would suggest is, rather than using the code to create an if statement, use the Succeeding rules in the Activity Wizard. It should allow you to create conditional statements that would let you choose whether to send the email or not.


 


Ian


Hi

 

This is my take on it. 

 

Sometimes it just makes more sense to modify the code than to create a big workaround in the designer.  Occasionally I need to modify the code in an event, similarily to what you describe, to enable some business requirement.  This is completely fine and works well and the modifications to the code will not be overwritten by K2 Updates.  What you would need to be concerned about is on the design canvas there is an option to Update Design templates.  This will cause any modified code to be overwritten by the "updated design templates".  I don't find this to be a big problem as I don't update the design templates across versions unless I know there is a known issue to be resolved.  However, to help mitigate the risk that someone else might do it you can add some agreed apon visual indication to the event name and/or activity by adding something like cc Mail Notification or changing the colour of the activity in the designer to Orange for example.  Of course this only helps when all the developers working on the process understand those conventions.

 

 

Note:  In the past I have submitted a feature request to add an event rules interface which would solve most of these situations that require the modifying of the event templates with custom code.

 

 


Thanks for your replies. I was worried that updating the design templates in particular would overwrite it. Thanks for confirming that it will overwrite it. That's a big problem for me. Lately, I find i am updating design templates a lot from cold fixes. I think I should stick to succeeding and line rules for now.

 

Thanks


Reply