Skip to main content

Notifications

Announcements

No record found.

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

  • 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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 91

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans