Friday, 27 January 2012

Creating workflow activity

Use CRM Development toolkit
and Select "New Visual Studio Solution Template for Dynamics CRM 2011"

add following references if not already added
Microsoft.Xrm.Sdk, Microsoft.Xrm.Sdk.Workflow, System.Runtime.Serialization
System.Activities, System.Activites.Presentation

Sign the assembly, and click deploy, In case you don't see custom activity/ updated field/ updated behaviour then ResetIIS


public class CustomActivity: CodeActivity
    {
        protected override void Execute(CodeActivityContext codeActivityContext)
        {
            IWorkflowContext workflowContext = codeActivityContext.GetExtension<IWorkflowContext>();
            EntityReference entityReference = new EntityReference
            {
                Id = workflowContext.PrimaryEntityId,
                LogicalName = workflowContext.PrimaryEntityName
            };

            IExecutionContext context = codeActivityContext.GetExtension<IExecutionContext>();
            IOrganizationServiceFactory serviceFactory = codeActivityContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


            Entity entity = service.Retrieve(entityReference.LogicalName, entityReference.Id, new ColumnSet(new string[] { "new_attribute1", "new_attribute2", "new_attribute3" }));

            EntityReference Lookup = (EntityReference)stepInstance[" new_attribute1"];

            Entity entity2= service.Retrieve(Lookup.LogicalName, Lookup.Id, new ColumnSet(new string[] { "new_attribute1" }));
            int maxStageDurationDays = (int) entity2 [" new_attribute1"];

             int numberOfDays = NumberOfDays.Get(codeActivityContext);
           //some calculations...
                DaysExceeded.Set(codeActivityContext, totalDays);
        }

        [Output("Days Exceeded")]
        public OutArgument<int> DaysExceeded { get; set; }
       
        [RequiredArgument]
        [Input("Number Of Days")]
        public InArgument<int> NumberOfDays { get; set; }
    }


http://luckyabhishek.blogspot.com/2010/12/crm-2011-beta-creating-workflow.html

http://andreaswijayablog.blogspot.com/2011/09/crm-2011-custom-workflow-activity-send.html

No comments:

Post a Comment