Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

First of all, a little explanation what this is about:
I'm currently trying to write a custom workflow activity for use in SharePoint Designer 2010. I've got a column in my list - let's call it "approversColumn" - that stores several users and groups. If a new task is added while the (feedback or approve) workflow is running (like through delegating an existing task to another person) this person (assignedTo parameter of the task, I think) should be added to the existing users and groups in the approversColumn.

Since I wasn't able to accomplish this with existing SharePoint Designer activities, I decided to write a fitting one for this purpose. The problem is, that I don't have much experience with SharePoint related developing. So please forgive me if some of the questions seem really basic.
I have some ideas how the activity could look like, but am not quite sure about it.

Current status & problems:
I already set up the basic activity and could deploy it successfully so that it shows up in SharePoint Designer. The problem now is how to create the underlying logic.

One idea was to just get the contents of the mentioned fields, append one to the other and write the result back into the approversColumn. But:

What type should I use for the DependencyProperties?
How do I get the contents of the approversColumn?
How do I get the assignedTo parameter of the task?
And how do I write the result back to the approversList column?

Another idea was to pass the column name to the activity and let it get the content of that column itself, since I have access to the list via the workflow context. But then I still need the assignedTo parameter, of which I have no idea how to get that.

Edit:
This is how my .actions file looks so far:

    <?xml version="1.0" encoding="utf-8" ?>
<WorkflowInfo>
  <Actions>
    <Action Name="Merge Users"
        ClassName="MergeUserActivity.MergeUser"
        Assembly="MergeUserActivity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=131c449c41275d01"
        Category="My Custom Activities"
        AppliesTo="all">
      <RuleDesigner Sentence="Merge %1 and %2 (output to %3)">
        <FieldBind Id="1" Text="users1" Field="UserSource1" />
        <FieldBind Id="2" Text="users2" Field="UserSource2" />
        <FieldBind Id="3" Text="field" Field="UserTarget" />
      </RuleDesigner>
      <Parameters>
        <Parameter Name="UserSource1" Type="Microsoft.SharePoint.WebControls.Peopleeditor, mscorlib" Direction="In" Description="First user source." />
        <Parameter Name="UserSource2" Type="Microsoft.SharePoint.WebControls.Peopleeditor, mscorlib" Direction="In" Description="Second user source" />
        <Parameter Name="UserTarget" Type="Microsoft.SharePoint.WebControls.Peopleeditor, mscorlib" Direction="Out" Description="Output field for merged users." />
        <Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" Direction="In" DesignerType="Hide" />
      </Parameters>
    </Action>
  </Actions>
</WorkflowInfo>

And this is the activity:

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;

namespace MergeUserActivity
{
    public partial class MergeUser : SequenceActivity
    {
        public MergeUser()
        {
            InitializeComponent();
        }

        #region Fields

        public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(MergeUser));
        public static DependencyProperty UserSource1Property = DependencyProperty.Register("UserSource1", typeof(SPFieldUserValueCollection), typeof(MergeUser));
        public static DependencyProperty UserSource2Property = DependencyProperty.Register("UserSource2", typeof(SPFieldUserValueCollection), typeof(MergeUser));
        public static DependencyProperty UserTargetProperty = DependencyProperty.Register("UserTarget", typeof(SPFieldUserValueCollection), typeof(MergeUser));

        #endregion

        #region Properties

        [ValidationOption(ValidationOption.Optional)]
        public WorkflowContext __Context
        {
            get
            {
                return (WorkflowContext)base.GetValue(__ContextProperty);
            }
            set
            {
                base.SetValue(__ContextProperty, value);
            }
        }

        [ValidationOption(ValidationOption.Optional)]
        public SPFieldUserValueCollection UserSource1
        {
            get
            {
                return (SPFieldUserValueCollection)base.GetValue(UserSource1Property);
            }
            set
            {
                base.SetValue(UserSource1Property, value);
            }
        }

        [ValidationOption(ValidationOption.Optional)]
        public SPFieldUserValueCollection UserSource2
        {
            get
            {
                return (SPFieldUserValueCollection)base.GetValue(UserSource2Property);
            }
            set
            {
                base.SetValue(UserSource2Property, value);
            }
        }

        [ValidationOption(ValidationOption.Optional)]
        public SPFieldUserValueCollection UserTarget
        {
            get
            {
                return (SPFieldUserValueCollection)base.GetValue(UserTargetProperty);
            }
            set
            {
                base.SetValue(UserTargetProperty, value);
            }
        }

        #endregion

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {

            try
            {

                SPWeb currentWeb = this.__Context.Web;
                SPListItem currentItem = currentWeb.GetListItem(this.__Context.CurrentItemUrl);

                foreach (SPFieldUserValue us1_user in UserSource1)
                {
                    UserTarget.Add(us1_user);
                }

                foreach (SPFieldUserValue us2_user in UserSource2)
                {
                    UserTarget.Add(us2_user);
                }

                return ActivityExecutionStatus.Closed;
            }
            catch (Exception ex)
            {
                ISharePointService service = (ISharePointService)executionContext.GetService(typeof(ISharePointService));

                if (service == null)
                {
                    throw;
                }

                service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowError, 0, TimeSpan.Zero, "Error Occurred", ex.Message, string.Empty);

                return ActivityExecutionStatus.Faulting;
            }
        }
    }
}
share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.