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.
[Output("RecordId")]
public OutArgument<Guid> RecordId { get; set; }
[Output("RecordIdString")]
public OutArgument<string> RecordIdString { get; set; }
[Output("EntityName")]
public OutArgument<string> EntityName { get; set; }
[Output("PrimaryKey")]
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
Paul
If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".
