The other side of complexity

Simplicy in Software Design and Code

Request Entity Pattern or ‘CRM Wizards’

Posted by Chris Condron on January 1, 2010

In a number of  places in our CRM application we need to ensure that certain rules and conditions are met before allowing the creation of certain entities, primarily adding new accounts, long story. We also wanted to avoid creating custom aspx web pages to keep the deployment and maintenance simple as well, even longer story.

To solve this problem we eventually settled on a Request Entity Pattern where we gave users an AccountRequest entity with a small number of attributes that fires a server-side plug-in to create the account. Then some JavaScript in the request entity opens the newly created account and closes the request.

This pattern has proven to be tremendously useful in a number of situations so I thought I’d take a few minutes to walk through it. Primarily it provides an easy way to deal with onetime setup logic or constraints without making the target entity overly complicated. You in effect have a custom form just for the create and it also provides a number of extra injection points for plugins, JavaScript, and duplicate detection outside of the main entity. Finally it gives a built-in audit trail of each create request for key entities.

Example of an Request Entity Pattern for Account:

  1. Create a new custom entity Account Request, add attributes for the required fields on account and any others needed for account setup. Make sure that required fields on Account are also marked required on the Request entity. Add an N-to-1 relationship between AccountRequest and Account named LinkedAccount.  (You want a lookup field on the account form names LinkedAccount with the id of the Account in it.)
  2.  Remove the create security permission for the account entity from the users, add security permissions for create and update permissions to the new AccountRequest entity.
  3.  Add an ISV Button to the Account View called ‘New’ that opens a new AccountRequest. (The original new button will be hidden by security.)
  4.  Add java script on the AccountRequest to
    1. set the LinkedAccount attribute forcesubmit = true.
    2. check if the value in LinkedAccount, if it is not null open the linked account in a new window and close the request form. 
  5. Create a plugin for AccountRequest
    1. Register Pre-Stage of the parent pipeline for Create and Update, and use the false option on the CreateCrmService to run in the system context, (the user does not have privileges to create an account.)
    2. If the business conditions are met then create the new account, update the account lookup attribute in the target property bag with the ID of the new account, and set the owner of the account to the user, (it will default to SYSTEM.) The forcesubmit in step 4 above ensures the account lookup attribute will be in the property bag.
  6. Add custom business logic and duplicate detection as required to the AccountRequest Entity.

 Chris Condron

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.