locked
Inline code in a workflow? RRS feed

  • Question

  • Hi. Is it possible to write inline code in my workflow? E.g. I'd like to drop a scripting shape in to the workflow and write some code in to that shape. The closest I could find to this was a shape that calls my C# method.

    The ability to write inline code in a workflow is supported in BizTalk. I was hoping to find it in .Net 4 workflow. Have I missed something?

    Thanks!


    Myles Jeffery | Thinkscape | SharePoint Online Deployment | SharePoint Online File Migration Tool
    Friday, October 29, 2010 7:34 AM

All replies

  • Hi McGeeky,

    Yes, it is possible ;)

    To call a simple methode you could use the "InvokeMethod" activity.

    To call a code edit in workflow designer, the better way is to code a custom activity. This activity sould have a InArgument to allow you to put in you code via designer. In the execute methode you'll only have to call use context to schedule your argument (in fact : your custom code designed in workflow definition).


    Jérémy Jeanson MVP, MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Friday, October 29, 2010 8:12 AM
  • Hi Jérémy. Thank you for your response. So a custom code/script activity is not supported out of the box by .Net 4?

    If I created my own workflow activity as you describe, would the designer view give me code "awareness"/syntax highlighting? How would I execute the scripted code?

    Thanks!


    Myles Jeffery | Thinkscape | SharePoint Online Deployment | SharePoint Online File Migration Tool
    Friday, October 29, 2010 8:40 AM
  • No, a cusom code/script activity is not supproted out of the box by WF4.

    If you creat your own activity you'll have to use Visal Basic code in workflow designer, i'm not sure that is your first mind :(


    Jérémy Jeanson MVP, MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Friday, October 29, 2010 9:22 AM
  • Hi Jérémy. VB would be fine. But how would I go about compiling and running the code that was entered in to my custom activity? And would the designer give syntax highlighting etc. on that code or would I have to use a plain "text box" to enter the custom code in?

    Sorry for all the questions!

    Thanks.


    Myles Jeffery | Thinkscape | SharePoint Online Deployment | SharePoint Online File Migration Tool
    Friday, October 29, 2010 9:30 AM
  • If you are creating workflows in Visual Studio, and you could create a custom code activity, and add your code to the execute method, and then just use that activity in your workflow. If you are creating the workflows inside VS 2010 then this would be the simplest approach. If you need to add the code in some sort of rehosted designer then it becomes more complex and you would need to do some sort of script hosting, and provide an editor. Can you share more details of your scenario? Who is adding the code and what tools are they using? And we can see what the best approach is.

    Thanks,

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

    Friday, October 29, 2010 9:44 PM
  • Hi Steve. Thanks for your feedback. What I want to achieve is the experience that I get with BizTalk; particulary now that more and more of BizTalk is coming to .Net workflow. In BizTalk, I can drop in a "Scripting" shape in to my workflow. I double click the shape to open it and I can then enter some in-line C# code (well, in BizTalk its called XLANGS, but it is very similar to C#).

    It's a great way of adding in some custom code without having to create a separate class or static method, and have that code right there in your workflow where you can easily access it. In BizTalk, the code in the script shape has full context awareness/code completion & compiler support.

    I'd prefer not to have to create a custom activity to support this scenario; it would be great if it was available out of the box.

    Cheers.


    Myles Jeffery | Thinkscape | SharePoint Online Deployment | SharePoint Online File Migration Tool
    Friday, October 29, 2010 10:00 PM
  • Gotcha. How does the script interact with the values in the other activities in the workflow? Or is it totally stand alone? (I will check with the Biztalk WF guys here to see how it works). If it is just stand alone code that does need values in or out from the rest of the workflow, that makes it simpler. I've got a few ideas, there may be a way to enter visual basic code and have it evaluated as an expression, what sort of code do you need to execute? Single expressions or multi-line routines?

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

    Saturday, October 30, 2010 12:03 AM
  • Hi Steve. The code in BizTalk can interact with the messages & variables declared in the workflow (in BizTalk terminology a workflow is called an orchestration) so its not standalone. Code can also be multiline. Check out this screenshot, you can see that the script/expression shape has been opened in the BizTalk workflow:

    http://www.seroter.com/BlogPics/07.05.2006dynamic1.jpg

    The Visual Basic code evaluated as an expression sounds along the lines that I need. Would be very interested to hear back from you after your chat with the BizTalk guys!

    Thanks.


    Myles Jeffery | Thinkscape | SharePoint Online Deployment | SharePoint Online File Migration Tool
    Saturday, October 30, 2010 7:47 AM
  • Hi, I am still following up on this. I am pretty sure you could be able to evaluate single line VB Expressions, still looking into the multi-line expressions (which I think maps more closely onto what the Biztalk Scripting shape can do)

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Tuesday, November 2, 2010 2:34 PM
  • Thanks Steve, I really appreciate it!
    Myles Jeffery | Thinkscape | SharePoint Online Deployment | SharePoint Online File Migration Tool
    Tuesday, November 2, 2010 2:40 PM
  • Hi Myles,

    Could you add inline code in your workflows?

    I would like to do the same, using a custom activity with an ExpressionTextbox multiline.  And then adding code inline in order to be executed in the Execute method of the activity.

    Thanks,

    Marc

     

    Wednesday, June 29, 2011 4:04 PM
  • Hi Marc. No - I stuck to calling static methods instead. It's a shame as I really like the inline scripting feature of BizTalk and miss it when working with WF.
    Myles Jeffery | Office365 MVP | Thinkscape | SharePoint Online File Migration Tool
    Wednesday, June 29, 2011 4:18 PM