web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM 2013 Custom Workflow and AutoMapper

(0) ShareShare
ReportReport
Posted on by 100

Hi,

I am looking for some examples on how to initialize AutoMapper in a Custom Workflow. 

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Marius Agur Pedersen Profile Picture
    1,771 on at

    Automapper's mapper method is stateful and not thread safe, so you should not use it for custom workflows. The CRM SDK specifies that Microsoft CRM caches the custom workflow instances (as well as the plugin instances), so the Execute method should only contain thread safe, stateless components.

    If you need to map records in your custom workflow you should add your own mapper functions. If you're copying whole records you could look into MemberWiseClone, which is a shallow copy function inherited from System.Object

    https://msdn.microsoft.com/en-us/library/system.object.memberwiseclone%28v=vs.110%29.aspx

    More information about thread safe/stateless plugins and custom workflows can be found here:

    https://msdn.microsoft.com/en-us/library/gg328515.aspx

    "For improved performance, Microsoft Dynamics CRM caches custom workflow activity instances. The custom workflow activity’s Execute method should be written to be stateless because the constructor is not called for every invocation of the custom workflow activity. Also, multiple system threads could execute the custom workflow activity at the same time. All per invocation state information is stored in the context, so it is not recommended to use global variables or member variables to pass data from one invocation to the next"

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans