Copied to clipboard

Flag this post as spam?

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


  • James Shannon 9 posts 29 karma points
    Nov 13, 2011 @ 19:14
    James Shannon
    0

    Email task to document author?

    Darren,

    Just created a basic workflow and it works fine, but one obvious question came out of this - whilst approval emails would normally target a specific user or user type, any approval/rejection email notifications would likely need to go to the author of the document attached to the workflow. How does one specify the document author as the recipient of an email task - I can only select a specific user or user type?!

    Thanks,

    James

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Nov 13, 2011 @ 20:56
    Darren Ferguson
    0

    Hi James,

    I'd introduce a new task and an accompanying entity UI - The task below sets the users to send to programatically by first adding the workflow instantiator and then looping all attached documents and adding their owner.

    The entity UI just removes the choice of users and usertypes to send to because it doesn't make any sense in this case.

    Let me know if you have any questions. I've built and tested this - you should be able to just drop the DLL into your /bin folder. I'll add this code to my next patch release as it makes perfect sense for this to be a default task!

    I've also posted the code at: http://static.darren-ferguson.com/example.zip

    using System;

    using System.Collections.Generic;

    using FergusonMoriyam.Workflow.Interfaces.Domain;

    using FergusonMoriyam.Workflow.Umbraco.Domain;

    using FergusonMoriyam.Workflow.Umbraco.Domain.Task;

    using umbraco.cms.businesslogic.web;

    using FergusonMoriyam.Workflow.Interfaces.Application.Runtime;

     

    namespace FergusonMoriyama.Workflow.Sample

    {

        [Serializable]

        public class InstantiatorEmailWorkflowTask : BaseEmailWorkflowTask, IRunnableWorkflowTask

        {

            public string Body { get; set; }

     

            public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)

            {

                

                var workflow = (UmbracoWorkflowInstance) workflowInstance;

                Users = new List<int> { workflow.Instantiator };

     

                foreach(var nodeId in workflow.CmsNodes)

                {

                    var document = new Document(nodeId);

                    Users.Add(document.Creator.Id);

                }

     

                SendMail(Body + Environment.NewLine + GetAttachmentLinks(workflow.CmsNodes));

                runtime.Transition(workflowInstance, this, "done");

            }

        }

    }

     

    using System.Collections.Generic;

    using FergusonMoriyam.Workflow.Umbraco.Ui.Property.Email;

    using FergusonMoriyam.Workflow.Umbraco.Ui.WorkflowTaskUi;

    using FergusonMoriyam.Workflow.Interfaces.Ui;

    using FergusonMoriyam.Workflow.Interfaces.Application;

     

    namespace FergusonMoriyama.Workflow.Sample

    {

        public class InstantiatorEmailWorkflowTaskEntityUi : BaseEmailWorkflowTaskEntityUi, IWorkflowTaskEntityUi, IGlobalisable

        {

     

            public InstantiatorEmailWorkflowTaskEntityUi() : base()

               

            {

               

                UiProperties = new List<IWorkflowUiProperty>

                                   {

                                       (IWorkflowUiProperty) CreateGlobalisedObject(typeof (SubjectPropertyUi)),

                                       (IWorkflowUiProperty) CreateGlobalisedObject(typeof (FromPropertyUi)),

                                       (IWorkflowUiProperty) CreateGlobalisedObject(typeof (BodyPropertyUi))

                                   };

     

            }

     

            public override bool SupportsType(object o)

            {

                return o.GetType() == typeof(InstantiatorEmailWorkflowTask);

            }

     

            public override string EntityName

            {

                get { return TheGlobalisationService.GetString("my_custom_email_task"); }

            }

        }

    }

  • James Shannon 9 posts 29 karma points
    Nov 13, 2011 @ 22:36
    James Shannon
    0

    Thanks Darren - I'll give that a go - would make a great addition as a default task!

    Also, when I use a before-publish instantiation criteria I see the red speech bubble saying 'blocked by a 3rd party add-in' whereas I noticed in one of your screencasts a nicer (green) speech bubble stating that the workflow (title) had been started - how is this achieved, as it's a much nicer end user experience? Or is it simply related to what Umbraco event is used to instantiate the workflow - so impossible to achieve for publishing approval as the publish has to be blocked?

    Thanks,

    James

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Nov 13, 2011 @ 22:55
    Darren Ferguson
    0

    The installer should apply a patch to:

    ~/umbraco/umbraco.aspx

    it appends the following script directly before the closing body tag:

    <script type="text/javascript">
            <!--
            $().ready(function () {
    
                UmbracoSpeechBubble.prototype.DefaultShowMessage = UmbracoSpeechBubble.prototype.ShowMessage;
    
                UmbracoSpeechBubble.prototype.ShowMessage = function (icon, header, message, dontAutoHide) {
            header = header .replace(/error/i, "Info");
                    // 'save' alert(icon);
                    if ($('#' + this.id).is(':visible')) {
                        jQuery("#" + this.id + "Message").append('<h3>' + header + '</h3><p>' + message + '</p>');
                    } else {
                        this.DefaultShowMessage(icon, header, message, dontAutoHide);
                    }
                };
    
                UmbSpeechBubble = new UmbracoSpeechBubble("defaultSpeechbubble");
            });
           // -->
        </script>
    

    This has the affect of making the speech bubble chain. the default behaviour is to show only one message hence the ugly error.

    As you've had issues with the installer perhaps this patch wasn't applied?

  • James Shannon 9 posts 29 karma points
    Nov 13, 2011 @ 23:49
    James Shannon
    0

    Yes, that's in there OK.

    However, the sample custom email task above causes the following error in the dashboard - is this a naming conflict caused by the new entity UI?

    Server Error in '/' Application.


    An item with the same key has already been added.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.ArgumentException: An item with the same key has already been added.

    Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace: 

    [ArgumentException: An item with the same key has already been added.]
       System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
       System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +9382923
       System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) +11
       FergusonMoriyama.Workflow.Sample.InstantiatorEmailWorkflowTaskEntityUi..ctor() +35
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
       System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +72
       System.Reflection.RuntimeConstructorInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +450
       FergusonMoriyam.Workflow.Ui.WorkflowEntityUiResolver.Resolve(Object typeToFindUiFor) +206
       FergusonMoriyam.Workflow.Ui.Factory.WorkflowTaskUiAdapterFactory.CreateWorkflowTaskUiAdapter(IWorkflowTask adaptedTask) +142
       FergusonMoriyam.Workflow.Ui.Adapter.WorkflowTaskCollectionUiAdapter..ctor(IEnumerable`1 tasksToAdapt) +146
       FergusonMoriyam.Workflow.Umbraco.Web.Ui.EditDesign.OnLoad(EventArgs e) +178
       System.Web.UI.Control.LoadRecursive() +74
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

    Thanks,

    James

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Nov 14, 2011 @ 08:21
    Darren Ferguson
    0

    Hi James,

    Can you try downloading the version that is there now and copying the debug DLL in to your bin directory - I was updating the post while testing and I think our posts may have crossed.

    Let me know if the latest Debug DLL is OK?

    Thanks.

    Darren.

  • James Shannon 9 posts 29 karma points
    Nov 14, 2011 @ 11:24
    James Shannon
    0

    Darren,

    All working fine now with the latest debug dll.

    Many thanks,

    James

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Nov 24, 2011 @ 14:49
    Darren Ferguson
    0

    Hi James,

    I've updated workflow for Umbraco so the base email task - and hence all other OOTB email tasks now have two check boxes in their task properties:

    • Email Instantiator
    • Email Attached node owners

    Hope this helps. You can just install the latest version over the top of your old one.

Please Sign in or register to post replies

Write your reply to:

Draft