web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Test a CWA from a console application

(0) ShareShare
ReportReport
Posted on by 355

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);
    }
}

I have the same question (0)
  • Verified answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: Test a CWA from a console application

    Answer to your first question, please refer below code:

    EntityReference myCollection = new EntityReference("collection",  new Guid("d4800847-7e4e-eb11-bf68-000d3a9c7067");

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 130

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 118 Super User 2025 Season 2

#3
Erin Lubben Profile Picture

Erin Lubben 57

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans