locked
CRM 4.0 + Custom Workflow Activity Get Related Entity Record RRS feed

  • Question

  • Hi All,

    I would like to know, how to get related entity guid from custom workflow assembley ?

    For example, if I have email entity and I know there is a case entity associated with this email.

    I have the id of the email, how to query so that i get id of the associated case in Custom workflow activity?

    Thank you for your time.

    Monday, November 7, 2011 12:54 AM

Answers

  • Hi Sam,

    Will following line give me the related case caseid ? I still havne't deployed this code so can't test it due to the some other reason.

    I have tested this following line and its working. No need to write dependency property or query.(getting better understanding of the context object and EntityImages in custom workflow assembly !!)

    Guid regardingcaseid = ((Lookup)ctx.PrimaryEntityImage["regardingobjectid"]).Value;

    Thanks a lot for your input guys.

    Cheers

     

     

     

     

    • Edited by CRM Thirsty Tuesday, November 8, 2011 11:41 PM
    • Marked as answer by CRM Thirsty Tuesday, November 8, 2011 11:41 PM
    Tuesday, November 8, 2011 9:17 PM

All replies

  • I am not sure if i have understood your question clearly... Let me try though...

    I assume you are writing a workflow that would fire on the email entity. The workflow would receive the guid of the email on which it fires.

    You can then use the retrieve message to read the email. Most probably the regarding of the email would be set to case, you can read the regardingobjectid property of email. Check if the objecttypecode is case if so the id refers to the associated case.

    Another option is to design the workflow to accept input parameters and setup the workflow to pass emails regarding as the value to the input property.

    HTH

    Sam

     


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Monday, November 7, 2011 5:43 AM
  • Hi Sam,

    Here is what i am trying to achieve.

    1. I am writing custom workflow on email entity.

    2. I know that email has one Case assoicated with it. (thru 'Conver to Case' button on email record)

    3. I want to get the ID of this Case so I can build the url of this case and send it to user in a workflow email.

    To achive above, I am writing custom workflow in which I can get emailID.

    now I want to query Case entity like ' select CaseID where CaseID = regardingobjectid' and want to return this CaseID.

    BUT, as you have said if regardingobjectid is the caseid then I don't have to write this query. Right?

    in that case how do i read properties of email record in custom workflow ? does PreImage will give me all the attributes ?

    I am getting emailID from following code.

    ===============================================================

    IContextService

     

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

    ));

     

    IWorkflowContext

    ctx = contextService.Context;

     

    ICrmService service = ctx.CreateCrmService(true

    ); ;

    // Get the record id from the context

     

    Guid

    id = ctx.PrimaryEntityId;  // How to get rest of the attributes. like regardingobjectid

    ==============================================================================

    I know in plugin it's easy but haven't familier with custom workflow.

    appreciate your time

    Cheers 

     

     

     

    Monday, November 7, 2011 9:59 PM
  • Hi

    You need to define regardingobjectid as DependencyProperty in side the workflow as follows and then in the workflow designer you need to map the regardingobjectid attribute against this property. Please look at the sample code below to understand the usage. Hope this help you.


    namespace My.Workflow
    {
        	[CrmWorkflowActivity("Process Sync WorkQueuePackage Items", "My Workflow Library")]
    	public partial class WorkQueuePackageActivity: SequenceActivity
    	{
    		public WorkQueuePackageActivity()
    		{
    			InitializeComponent();
    		}
    
            public static DependencyProperty PackageIdProperty =
                DependencyProperty.Register("PackageId", typeof(Lookup), typeof(WorkQueuePackageActivity));
    
            [CrmInput("WorkQueue Package Id")]
            [CrmReferenceTarget("okn_workqueuepackage")]
            public Lookup PackageId
            {
                get
                {
                    return (Lookup)base.GetValue(PackageIdProperty);
                }
                set
                {
                    base.SetValue(PackageIdProperty, value);
                }
            }
    
            public static DependencyProperty PackageStatusProperty =
                DependencyProperty.Register("PackageStatus", typeof(Picklist), typeof(WorkQueuePackageActivity));
    
            [CrmInput("WorkQueue Package Status")]
            [CrmReferenceTarget("okn_workqueuepackage")]
            [CrmAttributeTarget("okn_workqueuepackage", "okn_status")]
            public Picklist PackageStatus
            {
                get
                {
                    return (Picklist)base.GetValue(PackageStatusProperty);
                }
                set
                {
                    base.SetValue(PackageStatusProperty, value);
                }
            }
    
            
            protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
            {
    
                if ((PackageStatus.Value != enumCreatedStatus) && (PackageStatus.Value != enumReQueuedStatus))
                    return ActivityExecutionStatus.Canceling;
    
    
                IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
                IWorkflowContext context = contextService.Context;
                ICrmService crmService = context.CreateCrmService();
    
    
                try
                {
                    if ((PackageStatus.Value == enumCreatedStatus) || (PackageStatus.Value == enumReQueuedStatus))
                    {
                        
                            WorkQueuePackage package = WorkQueue.RetrievePackage(crmService, PackageId.Value, ref vr);
                    }
    
                    return ActivityExecutionStatus.Closed;
                }
                catch (SoapException soEx)
                {
                    return ActivityExecutionStatus.Canceling;
                }
                catch (Exception ex)
                {
                    return ActivityExecutionStatus.Canceling;
                }
                finally
                {
                }
            }
    
    	}
    
    }
    
    



    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Tuesday, November 8, 2011 12:28 AM
  • One way is to accept an input parameter in the workflow as explained by Thomas in the code below. 

    If you find it difficult to setup input parameter, you can execute a retrieve message and read all details of the email.

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Tuesday, November 8, 2011 9:13 AM
    Tuesday, November 8, 2011 9:13 AM
  • Hi Sam,

    Will following line give me the related case caseid ? I still havne't deployed this code so can't test it due to the some other reason.

    I have tested this following line and its working. No need to write dependency property or query.(getting better understanding of the context object and EntityImages in custom workflow assembly !!)

    Guid regardingcaseid = ((Lookup)ctx.PrimaryEntityImage["regardingobjectid"]).Value;

    Thanks a lot for your input guys.

    Cheers

     

     

     

     

    • Edited by CRM Thirsty Tuesday, November 8, 2011 11:41 PM
    • Marked as answer by CRM Thirsty Tuesday, November 8, 2011 11:41 PM
    Tuesday, November 8, 2011 9:17 PM