Uncategorized

How Timeout Until with particular field works in Workflow Processes in CRM

Every System Customizer/Developer might have created a waiting workflow using Timeouts.

Just noticed one thing which made me think is it really working as expected.

Suppose I had a workflow on Create of Lead to wait till the Est Close Date as below:

2018-08-25 22_13_13-Process_ Lead - UpdateSendEmailNotification - Microsoft Dynamics 365

Now I created a Lead in my System suppose so that this workflow is triggered, and it waits till the Estimated Date. So, the Process Session looks as below:

2018-08-25 22_17_34-System Job_ Lead - UpdateSendEmailNotification - Microsoft Dynamics 365.png

So as per this the workflow is Waiting and Postpone until Estimated Date i.e. a Future Date.

Now suppose I change the Estimated Date to Present Date then what should happen?

CRM interestingly handles this scenario and causes the workflow to resume and execute the logic.

You can see the Process Session below:

2018-08-25 22_22_04-System Job_ Lead - UpdateSendEmailNotification - Microsoft Dynamics 365.png

So, as you see here the Postpone Date shows the same date whereas the Completed on Date represents the workflows completion Date.

So, CRM interestingly has a mechanism which keeps on checking whether the Timeout condition of the field is met or not and then executes accordingly by itself.

Hope you enjoyed CRM’s interesting fact. 😊

Uncategorized

Tip – Which Form Does Bulk Edit and Create/Update step in Workflow displays?

A simple question which 3 out of 10 System Customizers/Developers may answer correctly.

Suppose you are doing a Bulk Edit for contacts from the View a form with fields get displayed which looks as below:

2018-08-19 17_40_11-Contacts Active Contacts - Microsoft Dynamics 365 - Microsoft Dynamics 365

Similarly, if you add an Update Record step on a workflow on Contact record then you might see the same Form and fields without Headers as below:

2018-08-19 17_44_34-Contact_ Information - Microsoft Dynamics 365

So, if you ask which form fields the above form displays then you might say the Main Form. But its partially correct answer. As my Contact may have multiple Main Forms in the System.

2018-08-19 17_49_52-Customization - Microsoft Dynamics 365

So, the answer to this question is CRM follows the rule which it follows while opening the record of an Entity i.e. “It displays the last visited Form by the user for that Entity for which he/she is trying to Bulk Edit or trying to add Create/Update step of the particular Entity in a Workflow”.

Hope this helps 😊

Uncategorized

Alert – Changing Form Name of Forms used in Portal Configuration

Recently we encountered a strange issue in our Portal where the working Web Page started displaying not so descriptive but a generic error which many of you may have faced earlier for different reasons. So, the error looks as below:

2018-08-11 13_46_40-We're sorry, but something went wrong (500)This was a generic message. Thanks for the feature where we can now Disable the Custom error which is displayed above and can show the exact error in Portal. For more details on that you may refer the below link:

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/portals/view-portal-error-log

So, Disabling the Custom Error gave me the exact error in my case as you can see below:

2018-08-11 13_56_44-A form named Portal Lead Form couldn't be found on the entity lead.

This was strange as the configuration was working fine earlier and then it stopped working.  But the fact was that we had changed the form name from “Portal Lead Form” to “Extended Portal Lead Form”.

So, we opened the Entity Form to check the form selected on the record.

2018-08-11 14_10_31-Entity Form_ Sales Lead Create

And there you can see the dropdown is blank and the Form Name field contains the old value i.e. Portal Lead Form which was causing the error.

So, the conclusion is if you are changing the Form Name of any Form which is used in Portal Configurations then make sure you update the records manually with the latest values.

Hope this helps 😊

Uncategorized

Unit Testing of Queries involving LINQ Joins with Fakes C#

Recently we encountered a scenario where we had join queries involved in our code.

So, the requirement we had to pass the data of the joined entities accordingly which would satisfy the code logic in our Unit Test.

But it was not as easy as we thought as there is a tricky part involved there.

Sample Plugin Code for which we will be creating Unit Test:

1

As you can see in our code we are querying the Contact entity and using Joins with the Account entity to read the Account Name along with Contact Last Name.

So, we will be adding the below code to send the record in the Response:

2

But the problem here was How to send the joined Entity’s value as if we don’t pass any value then it was showing null value in the returned query results.

So, we thought of going for AliasedValue concept. So we decided to pass “a.name” field in the attributes and set the value as below as in our Linq query we had used “join a” in the Linq query:

contactObj.Attributes[“a.name”] = new AliasedValue(Account.EntityLogicalName, “name”, “Test Sid”);

But still, it didn’t work. On further spending more time and debugging the request we found the tricky part involved:

3

So as you can see the Entity Alias name involved is “a_0” and not “a” so we changed the code to “a_0.name” as below and it worked like a charm 😊

4

The above example shows how it works when one join is involved. Just for more curiosity, I tried with below multiple joins query:

5.png

So, it returns the link entity information as below:

For 1st Join on Contact

6.png

For 2nd Join on Lead

7.png

From the above results, I came to know that joins in LINQ works in a bit different way!!

The entity alias name is populated based on the joins order in your LINQ Query starting from 0 and increasing further if the query contains more joins along with the variable used for the respective entities.

Hope this helps and ease your Unit Testing with Fakes.

Uncategorized

Unit Testing & Handling CRM Requests using Fakes C#

Recently we were working on Unit Testing using Fakes for our Plugin. We faced a strange issue while writing the Unit Test for code as we had request involved there.

We were using RetrieveAttributeResponse in our code. But we were unable to set the expected response in Unit Test as AttributeMetadata is a read-only attribute and we cannot set it using the standard way.

We found some alternative blogs which mentioned using Wrapper classes approach for the same:

http://www.alexanderdevelopment.net/post/2013/01/13/How-to-unit-test-C-Dynamics-CRM-interface-code-part-III

https://nishantrana.me/2014/01/25/unit-test-retrieveattributeresponse-in-crm-using-microsoft-fakes/

But I was not willing to change the code and use Wrapper classes for this. So, after investing my time in research I found that below approach and the code worked for us like a gem:

 

2018-07-05 19_05_58-CMHC.CRM - Microsoft Visual Studio (Administrator)

So as you can see here we just passed the ParameterCollection object to the response.Results property in the response with the parameter name as “AttributeMetadata” the property which I wanted to set along with the respective value.

And guess what it passed the corresponding value which I needed to set in the read-only property.

This approach can be used for any of the CRM request where the property is read-only.

Hope this helps.