Click here to Skip to main content
15,125,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

// Execute

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;
ExecuteLogic(service , //I need the encyclopedia of the current context here);                       
}




// ExecuteLogic
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);
 query.LinkEntities.Add(linkEntity);

 List<Entity> moviesInCollection = context.RetrieveMultiple(query).Entities.ToList();  
foreach (Entity movie in moviesInCollection )
{
   var tempCollectionId = movie.Attributes["collectionId"];
   if (tempCollectionId  == myCollection.Attributes["collectionId"])
   movie.Attributes["Title"] =  // change;                
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900