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.)
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.
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.
Note - TheWorkflowInstanceService and TheWorkflowRuntime can probably be referenced as WorkflowInstanceService.Instance and WorkflowRuntime.Instance in your code.
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.
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.)
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.
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.
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.
Excelent, Darren. I'll be standing by.
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.
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.
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!
is working on a reply...