460 likes | 620 Views
Minneapolis Office Developer Interest Group (MODIG). Raymond Mitchell Inetium. April 28, 2009 Custom Workflow Actions in SharePoint Designer. http://www.iwkid.com/. The Plan. Introduction You are here Feature Presentation Custom Workflow Actions in SharePoint Designer
E N D
Minneapolis Office Developer Interest Group (MODIG) Raymond Mitchell Inetium April 28, 2009 Custom Workflow Actions in SharePoint Designer http://www.iwkid.com/
The Plan • Introduction You are here • Feature Presentation • Custom Workflow Actions in SharePoint Designer • Next Topic Selection • Random Stuff
User Group Goals • Provide a community for SharePoint Developers • Share development knowledge • Exchange tips/tricks/other/free pizza • Add 2,000 List Items…. using a custom action
User Group Format • Presentations • 1-2 per meeting (targeting 1.25 Hours) • Hopefully Demo Heavy (Slides are for MBAs) • Highlights of Nifty Things • See next slide • QA/Discussion/Random Things
Call for Cool Stuff • Created something cool? • Send Screenshots or Videos • We’ll try to feature some items here
Sharepointmn.com/modig/ • Our current home • Meeting information • Usually has the right time • Previous presentations • Running on SharePoint • As required by SharePoint User Group Law
Upcoming • Next Meeting • July 28 (Tuesday 5:30pm) • Topic: TBD – Hopefully later today • Location: Based on Feedback • MNSPUG • May 13 (9:00am – Noon) • Topic : Business Process / Workflow/ Forms(sharepointmn.com)
The Plan • Overview • SharePoint Designer Workflows • Actions and Conditions • How does it know? • Let’s build! • Create a custom action • Related: web.config modifications • Deploy a custom action via Solution • Build and deploy a custom condition • Would you like to know more? • Custom Actions available on CodePlex • Resources • Questions
SharePoint Designer Workflows • String together a series of action and condition “sentences” to build a custom workflow • A number of Actions and Conditions ship with Windows SharePoint Services • Visual Designer:
SharePoint Designer Workflows DEMO Out of the box SharePoint Designer Workflow
SharePoint Designer Workflows DEMO Behind the scenes – webpartpages.asmx?? ACTIONS file
Adding Custom Actions • High Level Steps: • Build an Activity • Sign your assembly and deploy to the GAC • Create an ACTIONS File • Update web.config file to add an authorizedType
Build an Activity • Activity class (System.Workflow.ComponentModel) • DependencyProperties • ActivityValidators • Add attribute to your class: [ActivityValidator(typeof(ValidatorClassName))] • Returns a ValidationErrorCollection to provide fancy error messages in SharePoint Designer
Sign your Assembly, Deploy to GAC • .snk file • .NET Framework 2.0 Configuration: • C:\Windows\Assembly • gacutil.exe • Microsoft .NET Framework SDK
Create an ACTIONS file • WorkflowInfo • Conditions • Condition • Assembly • ClassName • FunctionName • RuleDesigner • Parameters • Actions • Action • Assembly • ClassName • Category • RuleDesigner • Parameters
Create an ACTIONS file • RuleDesigner • Sentence • Populate %1 with %2 • %# maps to FieldBind • Can be various types as defined in FieldBind
Create an ACTIONS file • RuleDesigner • Sentence • FieldBind • FieldBind • DesignerType • Field • Text • Id
Create an ACTIONS file • Parameter • Type • System.String • Microsoft.SharePoint.WorkflowActions.WorkflowContext • System.Collections.ArrayList • System.Int32 • System.Boolean • … • Name • Maps parameter to a FieldBind • Direction • (In or Out)
Sample .ACTIONS File <?xmlversion="1.0" encoding="utf-8"?> <WorkflowInfoLanguage="en-us"> <ConditionsAnd="and" Else="Else If" Not="not" Or="or" When="If"> <ConditionAppliesTo="list" Assembly="Assembly.Name, Version=0.0.0.0, Culture=neutral, PublicKeyToken=GUID" ClassName="Fully qualified class name" FunctionName="Boolean method nameimplemented in class" Name="Name to be displayed in workflow editor“ Type="Advanced" UsesCurrentItem="true"> <RuleDesignerSentence="Sentence to be displayed to the workflow editor"> <FieldBindDesignerType="Date" Field="Parameter that FieldBind maps to“ Function="true" Id="Unique positive Integer“ Text="Text to be displayed as a hyperlink" TypeFrom="Parameter that a non-Operator derives its type from“ Value="Reserved for future use"> <OptionName="Option1" Value="Value1" /> </FieldBind> </RuleDesigner> <Parameters> <ParameterDirection="In" InitialValue="" Name="MyParameter" Type="System.String, mscorlib" /> </Parameters> </Condition> </Conditions>
Sample .ACTIONS File <Actions> <ActionName="Action name displayed in editor"> <RuleDesignerSentence="Sentence to be displayed to theworkflow editor"> <FieldBindDesignerType="CreateListItem" Field="Parameter that FieldBind maps to" Function="true" Id="Unique positive Integer" OperatorTypeFrom="Parameter Operator derives its type from" Text="Text to be displayed as a hyperlink" TypeFrom="Parameter non-Operator derives its type from" Value="Reserved for future use"> </FieldBind> </RuleDesigner> </Default> </Actions> </WorkflowInfo>
Add an authorizedType to Web.config • Add an authorizedType element to authorizedTypes: • Very similar to safe controls, except you can’t automate it with a solution manifest (<safeControl…)
Web.config Modifications • Should (almost) never, never, never make changes by hand • Manual changes are not “farm safe” • Manual changes are not “backed up” with SharePoint content • We need another challenge
Web.config Modifications • Enter SPWebConfigModification • Name – UNIQUE name of the modification • Xpath – path to the node being modified: configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes • Three Types: • Ensure Attribute • EnsureChildNode • EnsureSection • Owner • Important if you want to remove later!
Web.config Modifications • SPWebApplication • Add (modification) • Remove (modification) • SPWebApplication. WebService.ApplyWebConfigModifications() • SPWebApplication.Update()
SharePoint Designer Workflows DEMO Update a web.config using SPWebConfigModification
Deploying Custom Actions • High Level Steps: • Generate a SharePoint Solution file • Web Application Scoped Feature • Feature Receiver to add web.config modifications
SharePoint Designer Workflows DEMO SharePoint Solution generation with Web App Feature
Adding context to your Actions • Parameters that can be added: • WorkflowContext__Context • Microsoft.SharePoint.WorkflowActions.WorkflowContext • __Context.Web • __Context.Site • These two can only be added if they are going to be used: • string ListId • intListItem
SharePoint Designer Workflows DEMO Add 2,000 list items to a related list
Adding Custom Conditions • Class with public static Boolean function • Same parameter options for context: • WorkflowContext context • string listId • intlistItem
SharePoint Designer Workflows DEMO Create a custom condition
Useful SharePoint Designer Custom Workflow Activities • CodePlex project - http://spdactivities.codeplex.com • Latest release January 2008 • Release contains Setup.exe and a SharePoint Solution file • Source Code is available to download or browse
Useful SharePoint Designer Custom Workflow Activities Email • Send Email with HTTP File attachment - Allows sending emails with attachments retrieved using a web request • Send Email with List Item attachments - Allows sending list item attachments as files attached to an email • Send Email Extended - Enhaced version of the OOTB activity. Allows you to specify the sender. Also does not break links in body. Permissions • Grant Permission on Item - Allows granting of specified permission level on a spicified item • Delete List Item Permission Assigment - Allows deleting of specified permission level assigment for a given user • Reset List Permissions Inheritance - removes any unique permissions assigned to an item by inheriting list permissions User • Lookup user info - allows to lookup properties in site's user information list for a given login
Useful SharePoint Designer Custom Workflow Activities InfoPath • Get InfoPath field inner text - allows to query InfoPath form data using XPath • Get InfoPath field inner xml - allows to query InfoPath form data using XPath • Set InfoPath field inner text - allows to change InfoPath form data using XPath • Set InfoPath field inner xml - allows to change InfoPath form data using XPath Other • Start Another Workflow - Starts another workflow associated with a list item • Copy List Item Extended Activity - Allows copying/moving list items and files cross site. Conditions • Is User a member of a SharePoint group - Checks if a given user is part of given sharepoint group • Is Role assigned to User - Checks if a user role is already assigned on the current list item
Useful SharePoint Designer Custom Workflow Activities DEMO Installing SPDActivities Creating Workflows using SPDActivities
Resources • Jeff Zhang’s blog post: “Add Your Own Custom Workflow Activities to SharePoint Designer 2007”http://tinyurl.com/c7s8yj • MSDN article: “Building Custom Workflow Conditions for SharePoint Designer”http://tinyurl.com/ca8qd6 • CodePlex project: “Useful SharePoint Designer Custom Workflow Activities”http://spdactivities.codeplex.com
Resources • SDK Document: “Importing Custom Actions Into SharePoint Designer”http://tinyurl.com/d9vxsa • Wesley Bakker’s blog post: “Web.config modifications with a SharePoint feature”http://tinyurl.com/dlzpuw • Ted Pattison.net blog post: “Using a Web Application Feature to Modify web.config”http://tinyurl.com/ct982f
Next Meeting Planning • Possible Topics • ? • ? • ?
Random Stuff Raymond Mitchell Inetium http://www.iwkid.com Feedback Forms/Giveaway Mingle, Eat, Feedback See you next time!