I created a Custom Workflow Activity to deactivate all entities of type "Movie" related to a specific entity of type "Collection,", i.e. this CWA will be called from the form of a specific Collection and will change the state of all the related movies to "Inactive".
The method "Execute" calls another method "ExecuteLogic" which contains the business logic and takes an input parameter of the target entity type: by doing so, I want to be able to test such a method from a console application by passing the GUID of a specific collection to it (instead than putting all the logic inside the Execute method, which cannot be tested for it runs under the workflow context)
I have the following issues and need help and tips on how to test it:
1)
First, I found the GUID of a specific entity by selecting "Email a link" from the entity form; in the next window, I took the value of "collection&id" from the URL shown:
myCrmDomain.crm.dynamics.com/main.aspx collection&id=d4800847-7e4e-eb11-bf68-000d3a9c7067 [...
In the program I declared an entity reference which refers to that specific collection but how can I pass the GUID to it? The compiler tells me that I "cannot convert from String to System.Guid".
Here is my line of code:
EntityReference myCollection = new EntityReference("collection", "d4800847-7e4e-eb11-bf68-000d3a9c7067");
2) Secondly, I called the method from my CWA and tried to pass the specific collection, but I can't convert from EntityReference to Entity :
MyWCANamespace.DeactivateMovies.ExecuteLogic(_service, myCollection);
How can I use my entity reference to test the method? Or alternatively, should I declare an entity instead than an entity reference?
Here is the complete code of my WCA:
public static void ExecuteLogic(IOrganizationService context, Entity myCollection) { QueryExpression query = new QueryExpression("movie"); query.ColumnSet = new ColumnSet(true); // all movies related to the target collection (join) LinkEntity linkEntity = new LinkEntity("collection", "movie", "collectionid", "collectionid", JoinOperator.Inner); query.LinkEntities.Add(linkEntity); List moviesInThisCollection = context.RetrieveMultiple(query).Entities.ToList(); // deactivate all the returned movies foreach (Entity m in moviesInThisCollection) { var tempCollectionId = m.Attributes["collectionid"]; if (tempCollectionId == myCollection.Attributes["collectionid"]) m.Attributes["statecode"] = new OptionSetValue(1); } }