Resources for IT Professionals > Dynamics Forums > CRM Development > CRM Workflow help! using one entity to update another
Ask a questionAsk a question
 

QuestionCRM Workflow help! using one entity to update another

  • Monday, January 05, 2009 3:08 PMbshah1985 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Monday, January 05, 2009 3:30 PMHassan Hussain Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Monday, January 05, 2009 3:34 PMbshah1985 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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!
  • Monday, January 05, 2009 4:42 PMHassan Hussain Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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=en


    You 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.aspx

    Hassan.
  • Monday, January 05, 2009 6:00 PMNaitik Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
  • Wednesday, January 07, 2009 10:31 AMbshah1985 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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! :-)

  • Wednesday, January 07, 2009 11:46 AMNaitik Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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;
            }

  • Wednesday, January 07, 2009 1:22 PMbshah1985 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    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!! :-)

  • Wednesday, January 07, 2009 5:14 PMNaitik Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    to debug workflow custom activity:

    http://msdn.microsoft.com/en-us/library/cc151143.aspx

     

  • Saturday, November 07, 2009 10:24 AMSebastian1234 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
    •  
  • Sunday, November 08, 2009 7:24 PMMayankP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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...