Hi all,
I hope to make a custom action for workflow and could be used in SPD 2010. This action takes 2 paramter, one is string another is date to query the calendar and return a string from an event title. The code is like this:
Imports System.Collections
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.UserCode
Imports Microsoft.SharePoint.Workflow
Namespace MyWorkflow.Actions
Public Class CalendarQuery
Public Function TestFunction(Context As SPUserCodeWorkflowContext, CalendarName As String, EventDate As Date) As Hashtable
Dim htResult As New Hashtable(1)
htResult.Add("Result", "Test")
Return htResult
End Function
End Class
End Namespace
Then I made an Element file in the VS project as this
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<WorkflowActions>
<Action Name="Return value test"
SandboxedFunction="true"
Assembly="$SharePoint.Project.AssemblyFullName$"
ClassName="MyWorkflow.Actions.CalendarQuery"
FunctionName="TestFunction"
AppliesTo="all"
UsesCurrentItem="true"
Category="Test Actions">
<RuleDesigner Sentence="From calendar [%2] on date [%1] get OT rate and put into [%3]">
<FieldBind Id="1" Field="EventDate" DesignerType="ParameterNames" Text="OT Date"></FieldBind>
<FieldBind Id="2" Field="CalendarName" DesignerType="ParameterNames" Text="Calendar Name"></FieldBind>
<FieldBind Id="3" Field="Result" DesignerType="ParameterNames" Text="Action Result"></FieldBind>
</RuleDesigner>
<Parameters>
<Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" Direction="In" DesignerType="Hide"/>
<Parameter Name="EventDate" Type="System.DateTime, mscorlib" Direction="In" />
<Parameter Name="CalendarName" Type="System.String, mscorlib" Direction="In" />
<Parameter Name="Result" Type="System.String, mscorlib" Direction="Out" DesignerType="ParameterNames"/>
</Parameters>
</Action>
</WorkflowActions>
</Elements>
The compile and deploy are succesfully finished. And the action is visible in SPD when making a list workflow. But the workflow always get error in the history, never complete.
My main reference are:
http://msdn.microsoft.com/en-us/library/ff798499.aspx
http://msdn.microsoft.com/en-us/library/gg615449.aspx
But these two articles have some conflict such as whether the function should be declared as 'Shared', which mean 'static' in c#.
Does any one has the idea about how to modify the code and the element file to make it work?
Alex Du