A while back I wrote a post about how you can use JavaScript and workflow to include an e-mail link for a newly created or updated record. While the method works, it was less than efficient and opened the door to more problems than solutions. There is a much better solution and it can be implemented rather quickly. It utilizes the .Net framework and the CRM 3.0 workflow engine to build the Url and update the record itself, plus it's more flexible and can be used in a variety of situations.
A few benefits of using the comination of CRM 3.0 Workflows and .Net:
- The .Net assembly created can be used in a manual workflow rule in order to update a bunch of records with the Url. The original method only allowed you to populate the Url on a record by record basis.
- It eliminates the user having to save the record twice to make sure the Url is populated on the entity
Step 1 - Create A Custom Attribute To Hold The URL
For this example we'll just call our attribute: new_urllink with datatype varchar or Url
Step 2 – Create the Custom .Net Workflow Assembly
Create a new class library project in Visual Studio 2003
namespace MicrosoftCRM.Examples.Workflow
{
public class UrlBuilder()
{
}
public void UpdateCaseWithUrl(Guid ticketid)
{
//Create CRM Service Reference
CrmService myService;
myService = new CrmService();
myService.Credentials = System.Net.DefaultCredentials;
myService.Url = "http://<crm_url>/mscrmservices/2006/crmservice.asmx";
incident myIncident = null;
//Retrieve Case From CRM
myIncident = (incident)myService.Retrieve(EntityName.incident,ticketid,new AllColumns());
//Populate the Custom Url Field
myIncident.new_urllink = “http://<crm_url>/cs/cases/edit.aspx?id=" + ticketid;
//Update the Case in CRM
myService.Update(myIncident);
myService.Dispose();
}
}
Step 3 – Deploy Code and Update the Workflow.config File
In order to use your custom .Net assembly within the CRM 3.0 workflow engine you need to first deploy the code and update the workflow.config file. Stop the Microsoft CRM Workflow service on the CRM Server. Copy and paste your compiled .dll to the folder below.
<install_drive>\Program Files\Microsoft CRM\Server\Bin\Assembly
Add the following entry at the end of the workflow.config file which you will find in the same directory that you deployed your .NET assembly. This entry will allow you to utilize your .NET assembly inside of the workflow designer.
<method name=”Update Case With Url”
<assembly=”MicrosoftCRM.Examples.Workflow.dll”
typename=”MicrosoftCRM.Examples.Workflow.UrlBuilder”
methodname=”UpdateCaseWithUrl”
group=”Url Builders”>
<parameter name=”Case” datatype=”Lookup” entityname=”incident”/>
</method>
Restart the Microsoft CRM Workflow service. If everything starts up ok, then you are in good shape.
Step 4 - Create The Associated Workflow(s)
To fully complete this you need to create 2 workflows. The reason I suggest 2 workflows is so the one that actual updates the entity and assigns the link can be run on demand in order to bulk-update multiple CRM records with the link.
Workflow #1: Create a manual workflow rule for Cases that simply calls the Custom .Net assembly method.
Workflow #2: Create the workflow that is going to send the e-mail notification. The first step should either be a call to the previous workflow that builds the Url or you can call the custom .Net workflow function from here as well.
Step 5 - Your Done!
A List of Common Url's For CRM Entities:
You can find the paths for CRM Entities rather easily by browsing to the home directory of the CRM Website, if it's installed on the default website the path would be <drive>\inetpub\wwwroot. Once you have access to the CRM Website files find the folders that contain the edit pages for the various entities:
- SFA - Sales Force Automation (accounts,contacts etc)
- CS - Customer Service (cases,contracts etc)
- MA - Marketing Automation (campaigns, marketing lists etc)
Sales Force Automation:
Accounts: http://<crm-url>/sfa/accts/edit.aspx
Contacts: http://<crm-url>/sfa/conts/edit.aspx
Leads: http://<crm-url>/sfa/leads/edit.aspx
Opportunities: http://<crm-url>/sfa/opps/edit.aspx
Marketing Automation
Campaigns: http://<crm-url>/ma/camps/edit.aspx
Marketing Lists: http://<crm-url>/ma/lists/edit.aspx
Campaign Response: http://<crm-url>/ma/campaignresponse/edit.aspx
Case Management:
Cases: http://<crm-url>/cs/cases/edit.aspx
Contracts: http://<crm-url>/cs/contracts/edit.aspx
KB Articles: http://<crm-url>cs/articles/edit.aspx
Custom Entities:
Custom: http://<crm-url>/userdefined/edit.aspx
*Please substitute the actual url of the CRM Implementation you are working with where you see <crm-url> in the links above.
Good Luck. I will be following up with a similiar post for Microsoft CRM 4.0 as well.
- Jeremy
** This posting is provided "AS IS" with no warranties, and confers no rights.
Posted
Jun 17 2008, 08:43 PM
by
Jeremy Winchell