CRM 2011 – How to copy a workflow

Today I needed to make a few workflows which were very similar to one I had already created.

I looked around CRM but I couldn’t see any copy functionality or a sneaky save as in the workflow (which you can do with lists).

I searched for the problem and there were a few blog posts but I didn’t understand quite what they were telling me because I couldn’t find the Activate as field (just under the Process name if you are wondering)

The solution is quite simple, you basically unpublish the workflow change it’s Activate As to Process template, publish it and then you can create copies of this workflow but only for workflows using the same entity, which when you think about it wouldn’t make any sense to create them for other entities.

This blog has a brilliant step by step process (with pictures)

http://nzregs.wordpress.com/2012/08/16/crm-2011-copying-a-workflow/

CRM 2011 – How to update hidden fields with a workflow

Workflows in CRM 2011 can only update fields which are visible on the form, if you create an entity update you are only allowed to pick the visible fields.

So what do you do if you want to update a hidden field?

  1. Go to the form, make the field/section visible.
  2. Save and publish the form
  3. create the update statement on the workflow, selecting the previously hidden fields
  4. Save the workflow and then publish
  5. hide the fields on the form, save and publish.

 

 

CRM 2011 – The difference between a plugin and a workflow

I was asked recently the difference between a plugin and a workflow and when it was best to use either.  At the time I was asked my mind went blank and I wasn’t sure.  In my mind they are both similar, so I set out to find out what the difference was.  The main difference I could think of was a workflow is asynchronous and it can fire off child workflows.

there was a good article about workflows and plugins for CRM 4 which you can read here

but then Gonzalo Ruiz has recently updated this and added in some dialog information as well, this is one of many great blog entries he has written recently

 

CRM 2011 – How to Schedule Recurring Workflows in CRM 2011

Gonzalo Ruiz has recently been writing some excellent CRM blog entries and he has just written another fantastic blog entry

Scheduling recurring workflows in CRM

On Richard Knudson’s blog he said that two of his most popular blog entries ever were based on creating a scheduled workflow in CRM 4.

So it was with interest when I saw the current blog entry on this subject and because there isn’t any scheduling tool within CRM but this is functionality that a lot of people would find useful.  This makes articles about scheduling interesting and useful to a lot of people working with CRM 2011.

Although below the instructions taken from the excellent blog post, he does attach some warnings and this is true because you have to be very careful about clogging up the ASYNC service because if you have ever experienced it going down you will know how important it is to CRM, if it shuts down or even slows down it’s a big problem.

WARNINGS:

  • Every time you create a recurring workflow, you should carefully consider what resource consumption implications it will have. Recurring operations tend to utilize a large amount of resources which can cause lagging to the CRM Asynchronous processing service.
  • You must select a primary entity for your workflow which will never be deleted, otherwise the entire recurring workflow will be cancelled. For example, you can set the primary entity of your workflow to be systemuser and trigger it the first time regarding your own system user.
  • There is a loop detection mechanism in CRM which would cancel processes/plugins that create infinite loops as the one above. The maximum depth for a recurrence/loop is 8; however, the depth is reset after 10 minutes of inactivity. Therefore, the workflow above should work fine because it has 1 month of inactivity so each time it executes the depth will be reset and it will never be cancelled by the loop detection mechanism.

1.  Define triggers:

Define the workflow as On-Demand and Child workflow (not automatic triggers)

2.  Define process:

Define the body of the workflow to represent the set of actions that must occur every month:

3.  Add the Wait:

Now you need a way to tell the workflow engine to repeat the process every month. To do so, I will first insert a wait step that will tell the workflow engine to wait for 1 month:

After the step, I need a way to “restart” the workflow. Since there are no while/for loops in the workflow designer, we must find another solution. I will simply create a recurrence pattern by having an “Execute child workflow” step which executes itself. Because the workflow is defined as a child workflow, it will call itself every month. After I activate the workflow it looks like this:

4.  Trigger the workflow once

The first time that the workflow executes, it must be triggered manually, after that it will schedule itself monthly from the time that it was executed manually. Since it is defined as an on-demand workflow, you can simply navigate to your primary entity and trigger the workflow manually.

5.  Verify

Once your workflow has been triggered for the first time, it should appear in the system jobs grid, waiting for the next month to resume execution:

Note that “month” is not the same as 30 days, it actually uses the calendar month definition, since CRM workflow uses the .NET DateTime class. Therefore, if it was first triggered the 1st of the month, it will always trigger the 1st of the month regardless of the number of days in a month.

CRM 2011 – Visual Studio Plugin Templates

Excellent blog post from someone who sounds like Pob but is actually Pogo69, he may have an unusual name but his blog is excellent.

he has published some Visual Studio templates for CRM 2011 and you can read about it here

Here are the links and installations instructions from his blog

The Templates

Custom Workflow Activity

http://www.mediafire.com/?5ai40s51qjqv24o

Plugin

http://www.mediafire.com/?ip9avvd5wnc87f0

How to Install

Simply copy the zip files (do not extract them – just copy the archives directly) into the folder:

<My Documents>\Visual Studio 2010\Templates\ProjectTemplates\Visual C#\CRM 2011\

I called my new folder ‘CRM 2011′ – you can call it what you wish.  The name you choose will appear as a new category when you create a new Visual Studio project:

CRM 2011 – Custom Workflow Syntax changes from CRM 4 to CRM 2011

[tweetmeme source=”BenHosk” only_single=false]

I am always interested in articles describing the differences between developing in CRM 4 and CRM 2011.  This is a common problem I have and it actually works both ways.

To start with I was trying to convert code examples in Javascript and Plugins from CRM 4 to CRM 2011 and finding that we use Entity instead of DynamicEntity etc.  The Javascript is completely different so I’m not going to mention that but if you want to know click the link below.

I also find myself getting confused when I have to do some coding in CRM 4 because I get used to working CRM 2011 and then I have to remember how to do things in CRM 4 again…

Here are the current syntax comparison blogs I have written

CRM 2011 – Syntax changes in plugins from CRM 4

CRM 2011 – Comparison between CRM 4.0 and CRM2011 script

Type Mapping Between Versions CRM 2011 and CRM 4

Now today I found this article explaining the differences between custom workflows in CRM 4 and CRM 2011, it’s an excellent article and the original can be found here but I have pasted the full article below because I would like it for my own reference


Differences in Custom Workflow Assembly in CRM 4.0 and CRM 2011

We have listed the list of changes noticed for designing a custom workflow assembly in CRM 2011 and in CRM 4.0.

1. References

CRM 4.0

using System.Workflow.Activities;

using System.Workflow.ComponentModel;

using System.Workflow.ComponentModel.Compiler;

using Microsoft.Crm.Sdk;

using Microsoft.Crm.Sdk.Query;

using Microsoft.Crm.SdkTypeProxy;

using Microsoft.Crm.Workflow;

CRM 2011

using System.Activities;

using Microsoft.Crm.Sdk.Messages;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Workflow;

2. Base Class

 

Base class definition has been changed from  SequenceActivity to CodeActivity.

CRM 4.0: In CRM 4.0 we have to specify both Workflow name and Workflowactivitygroupname in the code as written in the following code.

[CrmWorkflowActivity(“My Custom Workflow”, “CRM Workflow”)]

public class MyCustomWF: SequenceActivity

CRM 2011: In CRM 2011 that is done in different way.

public class MyCustomWF: CodeActivity

Both Workflow name and Workflowactivitygroupname can be specified at the time of registering the assembly as shown in below screen shot.

3. Execute Method

The overridden Execute method remains the same except parameter and return type.

 

CRM 4.0

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

 

CRM 2011

protected override void Execute(CodeActivityContext executionContext)

4. Create service

CRM 4.0

IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));

IWorkflowContext context = contextService.Context;

ICrmService crmService = context.CreateCrmService();

CRM 2011

IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

5. INPUT Parameters

CRM 4.0

Declaration: how to initialize the input parameter

// specified dependency property

public static DependencyProperty CaseIDProperty = DependencyProperty.Register(“CaseID”, typeof(Lookup), typeof(TotalTaskRetrieval));

// Specified Input property

[CrmInput(“Enter Case “)]

// Set the reference Target for Property created

[CrmReferenceTarget(“incident”)]

// Property Defined for caseId

public Lookup CaseID

{

get

{

return (Lookup)base.GetValue(CaseIDProperty);

}

set

{

base.SetValue(CaseIDProperty, value);

}

}

Use: Access the input parameter declared above as,

Guid caseid=CaseID.Value

CRM 2011

Declaration: how to initialize the input parameter

[Input(“Enter Case “)]

[ReferenceTarget(“incident “)]

[Default(“3B036E3E-94F9-DE11-B508-00155DBA2902″, ” incident “)]

public InArgument<EntityReference> CaseID { get; set; }

Use: Access the input parameter declared above as,

Guid caseid = CaseID.Get<EntityReference>(executionContext).Id

6. OUTPUT  Parameters

CRM 4.0

[CrmOutput(“outputSum”)]

public CrmMoney Sum

{

get

{

return (CrmMoney)base.GetValue(SumProperty);

}

set

{

base.SetValue(SumProperty , value);

}

}

CRM 2011

[Output(“outputSum”)]

[Default(“23.3”)]

public OutArgument<Money> Sum { get; set; }

How to create a repeating schedule workflow rule

I saw this blog post today by Yaniv Arditi, what I really liked about the solution was how simple and elegant it was.  It also used the functionaility in CRM, it reminds you about how useful and powerful workflows are.

I have put this on my blog so I can find this again because I’m sure that sometime in the future I will have to do something like this, in the past this has usually been done programming with .NET code, this solution offers an alternative to that.  It could be used by consultants who haven’t got access to a developer.

 

How to create a repeating schedule workflow rule

I am often asked by my clients if Microsoft Dynamics CRM 4.0 can automatically schedule and perform a repeating task, such as sending an email notification to a Contact every year or adding a Note to a Contact record every day.

One trivial solution to this problem is developing a custom module that will be repeatedly launched by Windows Scheduled Tasks feature or Windows Service and perform the required task.

Another solution, one that does not require writing code, can be implemented using the Work Flow engine.
Let’s take, for example, a scenario in which we would like to automatically send ‘Happy Anniversary’ email greeting to our Contacts on their Anniversary day.

The following 8 steps describe how to set up the required work flow rule:

1. Create a new blank work flow rule for the Contact entity

image

2. Set the rule to be triggered by both the record Creation and Attribute change events. Set the scope to user, at least until you have tested the rule.

image

3. Select the Anniversary attribute to trigger the record attribute change event

image

4. Add a Wait condition to wait until the Contact’s next Anniversary date

image

5. Add a ‘Send E-mail’ step, set the required email template (assuming you have one) and email details

image

6. Add an ‘Update Record’ step and set it to update the Contact’s anniversary date to next year Anniversary date

image

7. By the end, your work flow rule should look something like this:

image

8. Publish the work flow rule

9. Test the rule by creating a new pseudo Contact with a future date (e.g. tomorrow) as anniversary date and your email address. If all went well, you should be able to see a new rule instance waiting in the Contact’s workflows grid.
Past the target date, verify that the workflow rule has advanced and that you have received the greeting email. Also make sure the Contact’s Anniversary date has been updated to next year anniversary date.

 

CRM 2011 – Processes what are they?

I was doing some work in CRM 2011 and then I wanted to do a workflow.  I go to the customerization menu and I can’t find workflows.

You have to wonder why Microsoft constantly keeping not only changing the name of things but also moving them around.  You sometimes wonder if they go out of their way to make upgrading and using a new version difficult

Aha of course another tweak another complete renaming of things.

I don’t know why I didn’t realise Workflows would now be known as Process.  Then when you go in Process you can create a workflow!!  Although you can create a dialog as well.

There have been a few enhancements to workflows, you can run workflows on these entities

  • Connection
  • Connection Role
  • Goal
  • Queue Item
  • Recurring Appointment
  • SharePoint Site

You also get a to see Retry Count and Postponed until, which shows you how long the workflow is postponed until.

You get more error information, so instead of some mysterious error message you now get to see the full XML error message.

The final improvement I noticed is an admin screen for the workflow which has a tick box saying

“Automatically delete completed workflows to save space.

I haven’t used dialogs yet but if you want to read about that I found this article

http://ayazahmad.wordpress.com/2010/09/21/call-scripting-in-microsoft-crm-2011/