To create a custom activity that inherits from CodeActivity
- Start Microsoft Visual Studio 2010.
- On the File menu, click New, and then click Project.
- In the New Project dialog box, select Workflow under Visual C# in the Installed Templates pane, and then select Activity Library.
- Specify a name and location for the solution, and then click OK.
- Navigate to the Project menu and select Properties. On the Application tab, specify .NET Framework 4 as the target framework.
- Add references to the
Microsoft.Xrm.Sdk.dll
andMicrosoft.Xrm.Workflow.dll
assemblies. - Delete the Activity1.xaml file in the project.
- Add a class file (.cs) to the project. In Solution Explorer, right-click the project, select Add, and then click Class. In the Add New Item dialog box, type a name for the class, and then click Add.
Below is sample code for Cusotm workflow activity which will Accept 2 integeres as parameter and output will be total
namespace CreateEpiXml
{
public class createEPIXML : CodeActivity
{
[Input("Enter First Number")]
public InArgument<Int32> FirstNumber { get; set; }
[Input("Enter Second Number")]
public InArgument<Int32> SecondNumber { get; set; }
[Output("Total")]
public OutArgument<Int32> Total { get; set; }
protected override void Execute(CodeActivityContext context)
{
int fn = FirstNumber.Get<Int32>(context);
int sn = SecondNumber.Get<Int32>(context);
int total;
total = fn + sn;
Total.Set(context, total);
}
}
}
Sign the workflow assembly with .snk file ( similar to plugin )
Compile the project to create an assembly (.dll).
Register your custom workflow activity using Plugin Registration tool and u can access your activity from workflow / dialogs for execution.
using that custom workflow activity from workflow or dialog , you can pass this 2 integer numbers and read the output back in workflow/dialog.
Hope this helps
Vilas
No comments:
Post a Comment