I’m creating a CWA to retrieve the records of an entity, cycling each of them and change the value of the StateCode if a condition is satisfied.
In order to check the condition I should retrieve the entity from the context where my CWA is running, in order to compare the value of its attributes with those of the object I’m cycling, I don’t know how to retrieve this entity by knowing the context (as I’m only passing the CodeActivityContext as a parameter of the Execute method
More specifically, my entities are Movie and Collection, and a Movie can be inside a collection.
I want to retrieve all the movies which are inside a specific collection, and change their Title.
I passed a CodeActivityContext inside my Execute method,it calls another method (ExecuteLogic) which retrieve the result set of the join between movies and collections; foreach of these movies, if the collectionId of the current movie is equal to the collectionId of the current collection, the value of the attribute Title (of the movie) will change.
As the current collection is given by the workflow context, which method should I perform to retrieve this object?
Could it be correct to create an entity reference?
What I have tried:
protected override void Execute(CodeActivityContext context)
var workflowContext = context.GetExtension<IWorkflowContext>();
var serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
var service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
string entityName = workflowContext.PrimaryEntityName;
Guid entityId = workflowContext.PrimaryEntityId;
public void ExecuteLogic(IOrganizationService context, Entity myCollection)
QueryExpression query = new QueryExpression("movie");
query.ColumnSet = new ColumnSet(true);
LinkEntity linkEntity = new LinkEntity("collection", "movie", "collection", "collectionid", JoinOperator.Inner);
List<Entity> moviesInCollection = context.RetrieveMultiple(query).Entities.ToList();
foreach (Entity movie in moviesInCollection )
var tempCollectionId = movie.Attributes["collectionId"];
if (tempCollectionId == myCollection.Attributes["collectionId"])