Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicolás Cova 48 posts 120 karma points
    Jan 07, 2013 @ 15:34
    Nicolás Cova
    0

    How to get the value of CopyEventArgs.Document in a workflow?

    Hello everybody,

    I need a workflow to be executed after a user copies a node in the backoffice, so I have a workflow that is instantiated to the umbraco.cms.businesslogic.web.Document.AfterCopy event. Once the workflow is running, one of the tasks inside the workflow needs no modify some of the properties of the new document (the copy).

    I read that the CopyEventArgs.Document of the AfterCopy event is the copy, so how can I get that value from within my workflow?

    Thank you.

    (As a side note, I can't rely on relations to get the ID of the copy, because I can't guarantee that my users will always click on the "Relate copied items to original" checkbox.)

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Jan 09, 2013 @ 11:44
    Darren Ferguson
    0

    Hi Nicolás,

    Workflow wouldn't support that at the moment We would need to make a patch to do that - It sounds like a useful feature to have the instantiating event arguments in scope.

    We do need to release a new version shortly to be compatible with later versions of Umbraco.

    What are your timescales.

    Many Thanks.

  • Nicolás Cova 48 posts 120 karma points
    Jan 09, 2013 @ 14:16
    Nicolás Cova
    0

    Hi Darren,

    Thanks for your reply. I would greatly appreciate if this feature could be patched or included in the new version of the package. To answer your question, I'm afraid I have a very short timescale (around 15 to 30 days).

    Meanwhile, I'd like to ask you a new question: is there a way to (programatically) start or launch a workflow from an event handler? I thought that, while I wait for you guys to implement this feature, I could make an event handler for the AfterCopy event that would take the value of CopyEventArgs.Document and set it as the sender object of a new workflow instance and launch it. Is that possible? I think this could be a quick (albeit dirty) fix for my problem while I wait for a more elegant solution from you.

    Again, thank you.

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Jan 09, 2013 @ 14:57
    Darren Ferguson
    0

    Hi

    I can certainly provide a code sample of how to programtically instantiate a workflow. Your solution sounds more than feasible.

    Let me find one for you.

     

  • Nicolás Cova 48 posts 120 karma points
    Jan 09, 2013 @ 15:27
    Nicolás Cova
    0

    Excelent, Darren. I'll be standing by.

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Jan 09, 2013 @ 16:49
    Darren Ferguson
    100

    Should be like this:

     

     

    var inst = TheWorkflowInstanceService.Instantiate(workflowConfigId, comment);

     

                foreach(var id in ids)

                {

                    ((UmbracoWorkflowInstance) inst).CmsNodes.Add(id);

                }

                

                TheWorkflowInstanceService.Update(inst);

                TheWorkflowInstanceService.Start(inst.Id);

     

                TheWorkflowRuntime.RunWorkflows();

     

     

    Note - TheWorkflowInstanceService and TheWorkflowRuntime can probably be referenced as WorkflowInstanceService.Instance and WorkflowRuntime.Instance in your code. 

     

    Hope this helps.

  • Nicolás Cova 48 posts 120 karma points
    Jan 09, 2013 @ 16:53
    Nicolás Cova
    0

    Ok. I'll give it a shot in a couple of minutes. I'll get back to you to inform about the results.

    Thanks Darren.

  • Nicolás Cova 48 posts 120 karma points
    Jan 10, 2013 @ 16:42
    Nicolás Cova
    0

    It worked Darren. I was able to launch the workflow from my event handler with the code you provided. I'm looking forward to the next release of the package.

    Thank you very much!

Please Sign in or register to post replies

Write your reply to:

Draft