locked
SharePoint Workflow custom Activity

    Question

  • Hi all,

    I created a custom workflow action for SPD, but the problem is that it shows up in the list, but nothing happens when i click it, the sentence is not displayed.
    Can someone please tell me what i am missing.

    Code will be shown below, the following is being done when i deploy it:
    --> Copy dll to win->assembly
    -->copy actions file to ..\1033\workflows\
    --> web.config gets its authorized type
    -->iisreset 
    --> Restart SPD

    ACTIONS FILE:
    
    
    
    <?xml version="1.0" encoding="utf-8" ?>
    <WorkflowInfo>
      <Actions Sequential="then" Parallel="and">
        <Action Name="Gets AD fullname not domain name"
           ClassName="Onesys.TaskADWorkFlow"
           Assembly="Onesys.TaskADWorkFlow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1414f91d4d4e39bb"
           AppliesTo="all"
           Category="Onesys"
           UsesCurrentItem="true">
          <RuleDesigner Sentence="Set a variable from [%1] at [%2] into the variable [%3].">
            <FieldBind Field="SharePointList" Text="SharePointList" DesignerType="TextArea" Id="1"/>
            <FieldBind Field="ListItemID" Text="ItemID" DesignerType="TextArea" Id="2" />
            <FieldBind Field="PropertyValueVariable" DesignerType="ParameterNames" Text="Output 1" Id="3"/>
          </RuleDesigner>
          <Parameters>
            <Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" Direction="In"/>
            <Parameter Name="SharePointList" Type="System.String, mscorlib" Direction="In" />
            <Parameter Name="PropertyValueVariable" Type="System.String, mscorlib" Direction="Out" />
            <Parameter Name="ListItemID" Type="System.String, mscorlib" Direction="In" />
          </Parameters>
        </Action>
      </Actions>
    </WorkflowInfo>
    
    Coding in the cs file:

    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Collections;
    using System.Drawing;
    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.WorkflowActions;
    using Microsoft.SharePoint;
    
    namespace Onesys.TaskADWorkflow
    {
        public partial class ADWorkFlow : Activity
        {
            #region Internal properties
    
            public static DependencyProperty InvokeEvent
                = DependencyProperty.Register(
                "Invoke", typeof(EventHandler), typeof(ADWorkFlow));
    
            //sharepoint properties
            public static DependencyProperty SharePointListProperty
                = DependencyProperty.Register(
                "SharePointList", typeof(string), typeof(ADWorkFlow));
    
            public static DependencyProperty ListItemIDProperty
                = DependencyProperty.Register(
                "ListItemID", typeof(string), typeof(ADWorkFlow));
    
    
            public static DependencyProperty PropertyValueVariableProperty
                = DependencyProperty.Register(
                "PropertyValueVariable", typeof(string), typeof(ADWorkFlow));
    
    
            #endregion
    
            #region Workflow browsable properties
    
            [DescriptionAttribute("Invoke")]
            [CategoryAttribute("Invoke Category")]
            [BrowsableAttribute(true)]
            [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
            public event EventHandler Invoke
            {
                add
                {
                    base.AddHandler(ADWorkFlow.InvokeEvent, value);
                }
                remove
                {
                    base.RemoveHandler(ADWorkFlow.InvokeEvent, value);
                }
            }
    
            //sharepoint properties
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
            [ValidationOption(ValidationOption.Required)]
            [Browsable(true)]
            [Description("The SharePoint group name of users that must receive tasks")]
            public string SharePointList
            {
                get { return (string)base.GetValue(ADWorkFlow.SharePointListProperty); }
                set { base.SetValue(ADWorkFlow.SharePointListProperty, value); }
            }
    
    
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
            [ValidationOption(ValidationOption.Required)]
            [Browsable(true)]
            [Description("Current list item")]
            public string ListItemID
            {
                get { return (string)base.GetValue(ListItemIDProperty); }
                set { base.SetValue(ListItemIDProperty, value); }
            }
    
            #endregion
    
            #region SharePoint site properties
            public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(ADWorkFlow));
    
            [Description("__Context")]
            [ValidationOption(ValidationOption.Required)]
            [Browsable(true)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
            public WorkflowContext __Context
            {
                get
                {
                    return ((WorkflowContext)(base.GetValue(ADWorkFlow.__ContextProperty)));
                }
                set
                {
                    base.SetValue(ADWorkFlow.__ContextProperty, value);
                }
            }
    
            public static DependencyProperty ListIdProperty = DependencyProperty.Register("ListId", typeof(string), typeof(ADWorkFlow));
    
            [Description("ListId")]
            [ValidationOption(ValidationOption.Required)]
            [Browsable(true)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
            public string ListId
            {
                get
                {
                    return ((string)(base.GetValue(ADWorkFlow.ListIdProperty)));
                }
                set
                {
                    base.SetValue(ADWorkFlow.ListIdProperty, value);
                }
            }
            public static DependencyProperty ListItemProperty = DependencyProperty.Register("ListItem", typeof(int), typeof(ADWorkFlow));
    
            [Description("ListItem")]
            [ValidationOption(ValidationOption.Required)]
            [Browsable(true)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
            public int ListItem
            {
                get
                {
                    return ((int)(base.GetValue(ADWorkFlow.ListItemProperty)));
                }
                set
                {
                    base.SetValue(ADWorkFlow.ListItemProperty, value);
                }
            }
    
            [Description("PropertyValueVariable")]
            [ValidationOption(ValidationOption.Required)]
            [Browsable(true)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
            public string PropertyValueVariable
            {
                get { return ((string)(base.GetValue(PropertyValueVariableProperty))); }
                set { base.SetValue(PropertyValueVariableProperty, value); }
            }
    
            #endregion
    
            protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
            {
                this.RaiseEvent(ADWorkFlow.InvokeEvent, this, EventArgs.Empty);
                
    
                SPSite currentSite = (SPSite)this.__Context.Site;
                SPWeb currentWeb = (SPWeb)this.__Context.Web;
    
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(currentSite.ID))
                        {
                            //ons het nie hierdie nodig nie, want ons update niks nie
                            //site.AllowUnsafeUpdates = true;
                            using (SPWeb tempWeb = site.OpenWeb())
                            {
                                //ons het nie hierdie nodig nie, want ons update niks nie
                                //tempWeb.AllowUnsafeUpdates = true;
    
                                #region Magic Code
    
                                SPList tasks = tempWeb.Lists[this.SharePointList];
                                SPListItem item = tasks.GetItemById(Convert.ToInt32(this.ListItemID));
    
                                SPFieldUserValue uservalue = (SPFieldUserValue)item["AssignedTo"];
    
                                PropertyValueVariable = uservalue.User.LoginName.ToString();
    
                                #endregion
                                //ons het nie hierdie nodig nie, want ons update niks nie
                                //tempWeb.AllowUnsafeUpdates = false;
                                tempWeb.Dispose();
                            }
                            //ons het nie hierdie nodig nie, want ons update niks nie
                            //site.AllowUnsafeUpdates = false;
                            site.Dispose();
                        }
                    });
    
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message.ToString());
                }
                return ActivityExecutionStatus.Closed;
            }
        }
    }
    Thank you!
    JP
    • Moved by Mike Walsh FIN Tuesday, March 02, 2010 6:52 AM workflow questions go to the workflow forum (From:SharePoint - Development and Programming (pre-SharePoint 2010))
    Tuesday, March 02, 2010 6:51 AM

Answers

  • I ran into this problem this evening as well. 

    Have you tried removing the brackets around the placeholders within the sentence string.  I was using an example I had copied from someone else, howerver, it was using single quotes around the placeholders.  I removed the single quotes, and the sentence began showing up.  I believe I did have to perform an IIRESET, as well, close and re-open Sharepoint Designer.

    Instead of this:

    Sentence="Set a variable from [%1] at [%2] into the variable [%3]."

    Try this:

    Sentence="Set a variable from %1 at %2 into the variable %3.

    That at least solved my problem.

     

    • Edited by Mike Walsh FIN Wednesday, March 24, 2010 5:20 AM comment about proposed as answer (corrected) removed.
    • Marked as answer by Mike Walsh FIN Wednesday, March 24, 2010 5:21 AM
    Wednesday, March 24, 2010 3:24 AM
  • Hi Pat,

     

    I have resolved this. I did update of web.config at wrong port.

    • Edited by Mike Walsh FIN Saturday, April 30, 2011 6:22 AM New q removed.
    • Marked as answer by Mike Walsh FIN Saturday, April 30, 2011 6:23 AM
    Wednesday, March 24, 2010 2:50 PM

All replies

  • Did you update correct web.config?

    You need to update the web.config file to allow SharePoint Designer to use your custom action.

    http://msdn.microsoft.com/en-us/library/dd819165.aspx#odc_2007wss_bk_SPDesigner2007_Ch15_DeployConfigCustomAction

    Also the activity can not be added to workflow because activity throws exception.

    Comment all properties in activity and action file. Do you can add empty workflow?
    If yes, re-add property step by step, and you can find what is wrong.
    • Edited by OlegO. _ Tuesday, March 02, 2010 7:12 AM More info
    Tuesday, March 02, 2010 7:06 AM
  • Hi,

    I did update the web.config file on the correct port.
    Any other ideas why this could be happening?

    Greetings.
    Tuesday, March 02, 2010 7:13 AM
  • I am also facing same issue... I removed exception throwing code....

    Now sure what is wrong...
    • Proposed as answer by Pat Newgent Wednesday, March 24, 2010 3:04 AM
    • Unproposed as answer by Mike Walsh FIN Wednesday, March 24, 2010 5:20 AM
    Thursday, March 18, 2010 5:18 PM
  • I ran into this problem this evening as well. 

    Have you tried removing the brackets around the placeholders within the sentence string.  I was using an example I had copied from someone else, howerver, it was using single quotes around the placeholders.  I removed the single quotes, and the sentence began showing up.  I believe I did have to perform an IIRESET, as well, close and re-open Sharepoint Designer.

    Instead of this:

    Sentence="Set a variable from [%1] at [%2] into the variable [%3]."

    Try this:

    Sentence="Set a variable from %1 at %2 into the variable %3.

    That at least solved my problem.

     

    • Edited by Mike Walsh FIN Wednesday, March 24, 2010 5:20 AM comment about proposed as answer (corrected) removed.
    • Marked as answer by Mike Walsh FIN Wednesday, March 24, 2010 5:21 AM
    Wednesday, March 24, 2010 3:24 AM
  • Hi Pat,

     

    I have resolved this. I did update of web.config at wrong port.

    • Edited by Mike Walsh FIN Saturday, April 30, 2011 6:22 AM New q removed.
    • Marked as answer by Mike Walsh FIN Saturday, April 30, 2011 6:23 AM
    Wednesday, March 24, 2010 2:50 PM