get target id from on demand workflow activity RRS feed

  • Question

  • if I select a record and run a workflow on demand against it, how can I get the guid?

    will be the target ID or still the entityname+ID?

    if I create a activity that grabs this id to padd to a create email, can I just use a string type output?

    any code sample sugestions?

    Tuesday, September 3, 2013 7:55 PM

All replies

  • Do you want the GUID or the field name?

    Here is an example of how to get both. Keep in mind that the field name may not be 'entityname+ID' in all cases (for example activities), however in most other cases this is fine.

            public OutArgument<Guid> RecordId { get; set; }
            public OutArgument<string> RecordIdString { get; set; }
            public OutArgument<string> EntityName { get; set; }
            public OutArgument<string> PrimaryKey { get; set; }
            protected override void Execute(CodeActivityContext executionContext)
                // Create the context
                IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                // GUID of target record
                Guid recordId = context.PrimaryEntityId;
                string recordIdString = recordId.ToString();
                // Entity name and Primary Key field name (in most cases)
                string entityName = context.PrimaryEntityName;
                string primaryKey = string.Format("{0}id", entityName);
                // Set output parameters
                this.RecordId.Set(executionContext, recordId);
                this.RecordIdString.Set(executionContext, recordIdString);
                this.EntityName.Set(executionContext, entityName);
                this.PrimaryKey.Set(executionContext, primaryKey);

    Hope that helps


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    Tuesday, September 3, 2013 8:47 PM
  • that looks right, but would you have the same for CRM 4?
    Tuesday, September 3, 2013 9:57 PM
  • Pls refer this article.



    If my response helps you in finding your answer then please click 'Mark as Answer' and 'Vote as Helpful'

    Tuesday, September 3, 2013 10:38 PM