Saturday, 13 January 2018

Integration - Create a lead in CRM via a web service in 10 minutes

CRM (Microsoft Dynamics Online – not AX CRM) has an SDK which you could use to integrate to. It can been overwhelming sometimes. So, I decided to use Flow to do the communication for me (HTTP Request > Dynamics). Took me 10 minutes from start to finish.

I didn’t have to learn the CRM SDK or figure out how to do authentication etc. I wanted to send a simple json message like this.

{
     "Email": "munib@fakeemail.com",
     "FirstName": "Munib",
     "LastName": "Ahmed",
     "Topic": "Health"
}

Go to Flow and create a new HTTP request. Click on “Use sample payload to generate schema” and enter the above json message. It will generate a schema as per below screenshot. Take note of the HTTP POST URL that has been generated. We will use that later to send the message to.

image

In the Actions select Dynamics > “Create a new record”. Select Leads as the entity name. Map the fields and you are done.

image

Now we just need to send a message to Flow using the URL. It doesn’t matter what tool you use to send a message. Below I used AX2012 (just because I had this job from a previous blog post I did).

image

Go to Flow Run history to see what has happened. Notice in the output – it looks like the message we sent.

image

We see the same in the creation. The mapping has worked.

image

Final result in CRM is the lead created. All my mapped fields look fine.

image

A word of caution. This is not a production ready solution. As you should consider security and your end to end architecture.

I did this as a proof of concept and wanted to show the power of Flow. Allowing me to integrate to another system that I didn’t have much knowledge of.

Tuesday, 26 December 2017

Workflow hierarchy limit checker for D365FO

A couple of years back I wrote a post on a workflow hierarchy limit checker job. It was a simple job that took a starting worker and traversed up the hierarchy. It printed the userid/worker/position/manager/spending limit/approval limit in an info log.

Today I rewrote it slightly to use a dialog for D365FO. Since it is not possible to change the code that easily in D365. This currently only works for Expenses. Its not pretty at the moment but it works.

image

I intentionally left the error in there. This will print the same error as what the workflow engine would. Hopefully this would give you a clue on where it stops.

image

Hopefully I can come back and extend it to the other document types such as purchase requisition and purchase orders.

Code is available on GitHub. I gave it a generic name like “Workflow plus”. I hope to add a few other nice commonly used workflow enhancements to it.

Another common enhancement I can think of is - Purchase order spending and approval limit; currently you don’t have this on the document. It is not possible to create a stop condition based on approval/spending limits

You can run the job via the url. Later hopefully I can add a menu item and security to it.

Saturday, 16 December 2017

Run a class in background–Asynchronies mode

This is not much of a new thing but a reminder. I feel it should be used more often in D365fFO. In prior versions we showed a progress bar and gave the user a nice feeling that something was processing. In D365fFO we need better a way. If you look at the Data Management, it has a workspace for this. Process runs in async and workspace shows us the status.

Code wise, it is pretty simple. Below is an example from standard code. I got it using “Find reference” feature in Visual Studio.

image

Any info or error messages will appear in the message centre. This is great as the user can continue doing their job without waiting.

Why am I writing about this?

I had a project recently where the a process was taking minutes to run. Based on the amount of data and what it was doing, I found it acceptable that it ran that long. When the user was running it, they perceive it as slow and they are waiting on the screen to refresh. I used runAsync and what do you know – happy customer.

Monday, 4 December 2017

Show deleted items in Source Control Explorer

Common query I have seen a few times. Thought to share a simple tip.

There are times when items are deleted or moved to a different model. In that case you may need to see the deleted items to roll it back or see what was deleted. In visual studio, go to the Options and tick the flag to “Show deleted items in the Source Control Explorer”.

image

Alternatively click on this button. Thanks to Joris for pointing it out.

image

Tuesday, 7 November 2017

Analyse SQL performance issues using SQL Query Store for D365FO

Someone at work showed me this. With the production environment the Query Store is enabled. So when you bring it back to a sandbox environment. All that information comes with it.

If you connect to the database via SQL management studio. Then navigate to the Query Store. There is a lot of great in depth information you could get. I have a customer that has gone live for 3 months and I wanted to see if there were any improvements we could do. Such as missing indexes we could add to our product.

image

I won’t dive in too deep as there are some great resources online on how to utilise Query Store.

I should mention a lot of this information shows up summerised on LCS. So that should be your starting point but I am really glad this is available.

Friday, 27 October 2017

Chain of Command–next() gotcha

UPDATE: 31/10/2017

Microsoft reached out and I have to correct my example code. It seems the compiler does not catch it when it is 2 nested conditions. See below code.



Be careful when using Chain of Command not to place the next() call in a condition.

Here is an example.

Create a class extension for a form. Call the method init() but place it in an “if” condition. Something like this.

 [ExtensionOf(formStr(PurchReqCreate))]  
 final class PurchReqCreate_EAM_Extension  
 {  
   public void init()  
   {  
     info("Outer - Before next");  
     if (this.args() &&  
       this.args().record() &&  
       this.args().record().TableId == -100) //intentionally made it -100 to not execute this code  
     {    
       //doing something here  
       info("Inner - Before next");  
       if (this.args().record().TableId == -100)   
       {  
         info("Inside second if condition");  
       }  
       next init();  
       info("Inner - After next");  
     }  
     info("Outer - After next");  
   }  
 }  


The compiler will not error or give you a warning. However, at run time you will get a misleading error.

In my case I got this. “Error executing code: Wrong argument type for function.”

image

Having a look at Event viewer (Folder: AX-XppRuntime), it gave me a little more info. At least I know the class that was calling it. I searched for any customization.

image

I found an extension class PurchReqCreate_Extension. I was able to eye ball and figure out the problem. Taking next() outside the “if” condition.

Rewrote the same:

public void init()
{
  if (this.args() && this.args().record())
  {
    //
do something before
  }

  next init();

  if (this.args() && this.args().record())
  {
    //
do something after
  }

}

Sunday, 1 October 2017

First look at Azure Functions

Azure Functions allows you to write code that can be triggered by an event or timer. You don’t need a machine to run it on. All the computing runs on the Azure cloud ie sevrverless computing.

Below is a quick walk through. Keep in mind Microsoft has great documentation on their site. Just google it.

In this post I will put a simple walkthrough. Save you from the information overload.


Make sure you are using Visual Studio 2017.

Create a project of type “Azure Function”

image

Give it a minute to resolve the NuGet package. You will see a warning icon and watch it disappear by it self.

image

Once its done. Right click and Add item.

Select the type of function. The easiest to do is the Http trigger.

image

This will create a class with some sample code.

image

When you run it, it will run a local instance.

image

Navigate to the URL and watch it run.

image

There are many applications in the Dynamics space. Hopefully next time I can cover some Dynamics scenarios.