Custom fields in Custom workflow

By using custom workflow , i will make Auto-numbering in CRM 4.0 .

 

I have created a readonly field on Account entity” new_auto” to hold the “Guid” of

Account. As GUID is always unique , so there is no question about it being duplication. We can use prefix whatever we want.  As one can see AC- (GUID). I will use cutom workflow to obtain the GUID of entity when it is created and then update the entity with the prefix+ GUID.

 

 

 

 

 

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 Microsoft.Crm.Sdk;

using Microsoft.Crm.SdkTypeProxy;

using Microsoft.Crm.Workflow;

using Microsoft.Crm.Workflow.Activities;

using Microsoft.Crm.Sdk.Query;

 

namespace Number

{

      [CrmWorkflowActivity("OneTest", "AccountNumber")]

 

    public partial class Activity1 : SequenceActivity

    {

 

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

        {

 

 

            IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));

 

            IWorkflowContext context = contextService.Context;

 

      ICrmService crmService = context.CreateCrmService();

 

      WhoAmIRequest systemUserRequest = new WhoAmIRequest();

 

      WhoAmIResponse systemUser = (WhoAmIResponse)crmService.Execute(systemUserRequest);

 

      ColumnSet cols = new ColumnSet();

 //Getting the ID of entity which unqiue itself

 

      Guid guidID = new Guid(this.objectID.Value.ToString());

 

          // i am using “AC” before GUID.This field will hold the GUID of account

 

      string Number  = “AC-=” + guidID;

 

      TargetRetrieveAccount target = new TargetRetrieveAccount();

 

      target.EntityId = guidID;

      RetrieveRequest getAccount = new RetrieveRequest();

 

      getAccount.ReturnDynamicEntities = true;

 

      getAccount.Target = target;

 

      getAccount.ColumnSet = new AllColumns();

 

      RetrieveResponse retrieved = (RetrieveResponse)crmService.Execute(getAccount);

 

      DynamicEntity regardingAccount = (DynamicEntity)retrieved.BusinessEntity;

 //i am using custom field to hold the value of “GUID” .

 

      if (regardingAccount.Properties.Contains(“new_auto”))

      {

 

          regardingAccount.Properties["new_auto"] = Number;

 

      }

 

      else

      {

 

          regardingAccount.Properties.Add(new StringProperty(“new_auto”, Number));

      }

 

         crmService.Update(regardingAccount);

 

     

           return ActivityExecutionStatus.Closed;

 

        }

 

 

        public static DependencyProperty objectIDProperty = DependencyProperty.Register(“objectID”, typeof(Lookup), typeof(Activity1));

 

 

 

        [CrmInput(" objectID")]

 

       [CrmReferenceTarget("account")]

 

       // [CrmReferenceTarget("automatic.crm.new_audit")]

       // public.automatic.crm.Lookup

 

        public Lookup  objectID

        {

 

            get

            {

 

                return (Lookup)base.GetValue(objectIDProperty);

 

            }

 

            set

            {

 

                base.SetValue(objectIDProperty, value);

 

            }

        }

 

  }

}

Finally we need to publish the workflow using developer tool and then calling the assembly from workflow.

 

2 Responses to “Custom fields in Custom workflow”


  1. 1 Stu January 20, 2009 at 11:57 am

    So how would I do the same for a custom entity, not a system entity?


  1. 1 Retrieve Custom Fields | keyongtech Trackback on January 18, 2009 at 5:23 pm

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.