Friday, February 5, 2010

Auto-assigning workflow-created records to the current user

One of the 'features' of Dynamics CRM is that if you use a workflow to generate records, the owners of those records will be the author of the workflow, NOT the current user. Generally this is undesirable.

So how do we get around this? Without too much difficulty actually.

The trick is we can use the event trigger to tell us who the current user is. For example, let's say we have a workflow that creates a set of task records when a new account is created. While easy to set up, all the tasks will be owned by the workflow creator and not the user. However, as we know the user created the parent account (the event trigger), we can populate the task owners with the 'created by' of the parent account.

If the status of a record changes or the attributes are modified, use the 'modified by'. If the record is assigned, check the owner.

There you have it. A really easy way to assign workflow records to the current user and not the workflow administrator.

2 comments:

KK said...

How can I get the current user when you run an on-demand workflow?

I have a workflow that creates an appointment, and I want the organizer of the appointment to be the person who runs the workflow. How do I get that to happen?

Leon Tribe said...

For on-demand workflows, the owner of the created record is the person running the workflow. So you need to do two steps. One is to create the appointment. You then insert a second step to update the appointment. You will see the form assistant now lets you select fields from the created appointment record. So you populate the appointment organiser with the appointment owner.