CRM Workflow help! using one entity to update another
- Hello! I want to update all contact address details when for an account when the account's address details change. E.g. the contacts for an account have the same address as the account. I want to change ALL contacts address details for the account.
But i cant figure out how to create the workflow for it...any help much apprectiated! also, any other advice is greatly appreciated too!
thanks!!
All Replies
- You can update the "Primary Contact" Address fields when the account address field are updated by configuring the workflow. This is fairly straight forward.
If you want your workflow to update the address of all associated contacts you will need to write a custom workflow assembly in C#.Hassan. - oh ok...yeah i do ant to update ALL associated contacts to an account.
do you have any links to tutorial etc that mite be able to help me with this? (i am fairly new to it)
thanks for your help! - Download the MS CRM 4.0 SDK. There is a lot of sample code for creating Workflow assemblies.http://www.microsoft.com/downloads/details.aspx?familyid=82e632a7-faf9-41e0-8ec1-a2662aae9dfb&displaylang=enYou can also get help on calling an assembly in MS CRM 4.0 at the link below:http://blogs.msdn.com/jim_glass/archive/2008/04/30/calling-a-net-assembly-in-mscrm-4-0-workflows.aspxHassan.
Below is a post on how to create a sample workflow
http://www.stunnware.com/crm2/topic.aspx?id=CustomWorkflowActivity
and also
- thanks to everyone for your help! i've now managed to use the sdk to develop a workflow and successfully publish it to crm...
but it doesn't do what i want!
has anyone got any hints or tips on how i could retrieve a list of contacts associated to the account being modified, and then update all of their address to be the same as the accounts address?? like i said im very new to it and not really sure on how to go about it.
any help will be greatly apprecited! thanks again to everyone! :-) this can give u a start.
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
// Get the context service.
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
// Use the context service to create an instance of CrmService.
ICrmService crmService = context.CreateCrmService(true);
BusinessEntityCollection cts = RetrieveCts(crmService, context.PrimaryEntityId);foreach (DynamicEntity de in cts.BusinessEntities)
{
// Update each contact address details here.
}
return ActivityExecutionStatus.Closed;
}
private BusinessEntityCollection RetrieveCts(ICrmService service, Guid accId)
{
Microsoft.Crm.Sdk.Query.QueryByAttribute query = new Microsoft.Crm.Sdk.Query.QueryByAttribute();
query.ColumnSet = new Microsoft.Crm.Sdk.Query.AllColumns();
query.EntityName = EntityName.Contact.ToString();
query.Attributes = new string[] { "parentcustomerid" };
query.Values = new string[] { accId.ToString() };
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
retrieve.Query = query;
retrieve.ReturnDynamicEntities = true;
RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
return retrieved.BusinessEntityCollection;
}Hi!
I have used the following code and it doesnt seem to work(i know its not doing anything, I just want to make sure the workflow is running)...I have included a line to create a new txt file on my desktop (im not sure if you can do this!)...but when ever i change an accounts details the workflow doesnt seem to be running. i have set the workflow to run whenever a new account is created or one is modified. the only reason I have set the workflow to create a txt file is so I can check that it is working properly...but it isnt creating the file so I am assuming its not! any help??
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Collections.Generic;
using System.IO;using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Workflow.Activities;
using Microsoft.Crm.Workflow;
using Microsoft.Crm.Sdk.Query;namespace UpdateContactAddress
{
[CrmWorkflowActivity("Update Contact Addresses","Bipul's Customised Workflows")]
public partial class UpdateContactAddresses: SequenceActivity
{
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
File.Create(@"C:\Documents and Settings\Administrator\Desktop\workflow.txt");
IContextService contextService = executionContext.GetService<IContextService>();
IWorkflowContext workflowContext = contextService.Context;
ICrmService crmService = workflowContext.CreateCrmService(true);
QueryByAttribute query = new QueryByAttribute();
query.ColumnSet= new Microsoft.Crm.Sdk.Query.AllColumns();
query.EntityName=EntityName.contact.ToString();
query.Attributes=new string[]{"parentcustomerid"};
query.Values=new string[]{workflowContext.PrimaryEntityId.ToString()};
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
retrieve.Query=query;
retrieve.ReturnDynamicEntities=true;
RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)crmService.Execute(retrieve);
}
public UpdateContactAddresses()
{
InitializeComponent();
}
}
}is there anyway to debug it, so I can find where the error is occuring.
thanks you all once again!! :-)
- Hello,
i'm using the Cascading Wizzard from: http://www.gicrm.com/?categoryId=29264&itemId=78128
Cheap, easy install and help in a lot of problems to cascade information from a higher table to a lower table.
Don't forget to fire up a mass delete job for successful operations of the wizzard.
Cause it fills youre Async Table very fast if you had many accounts and contacts.
Sebastian1234- Edited bySebastian1234 Saturday, November 07, 2009 10:24 AMtype error
make sure following check list is followed and this will help you in debug this workflow ...
1-Ensure that your plug-in/workflow is signed
2-Rebuild the plug-in/workflow
3-run an iisreset command
4-copy the .pdb file and your .dll file to server\bin\assembly
5-Register the Plugin Registration Tool V2 (http://code.msdn.com/crmplugin)
Refer to your dll in bin\assembly
Make it disk deployment
6-Register the step
7-Register the image if needed
8-Open the plugin/workflow project and attach to w3wp.exe if Synchronous plug-in or to AsyncService if asynchronous plug-in/workflow...

