How to Fix the Binary Operator with Incompatible Types WebApi Error in Dynamics 365

Leave a comment
BEFORE WE START, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

In this post, we will look at how to fix the error “a binary operator with incompatible types was detected. Found operand types ‘Microsoft.Dynamics.CRM.account’ and ‘Edm.Guid’ for operator kind ‘Equal'”.

This error occurs when trying to access the WebApi. There are at least a couple of scenarios where this error can happen. Let’s look at these.

The first scenario is when you are trying to select a record by filtering the Id. For example, I have an account:

The URL of this account is: https://carl123.crm.dynamics.com/main.aspx?app=d365default&pagetype=entityrecord&etn=account&id=d2720425-53ad-43c3-b9dc-e7452b80ae13

We can see the Id is d2720425-53ad-43c3-b9dc-e7452b80ae13. To access this through the Web Api, we use below. Note the syntax – incorrect syntax may produce the error we are seeing:

https://carl123.crm.dynamics.com/api/data/v9.1/accounts?$select=name&$filter=accountid eq d2720425-53ad-43c3-b9dc-e7452b80ae13:

Next scenario, let’s say we want to select a record from our entity called new_accountbpf. A simple query gives us the results:

Now, the new_accountbpf entity has a field called bpf_accountid, which is a lookup to the Account field:

But, we can’t query this by passing an Account Id like we did above. E.g.

https://carl123.crm.dynamics.com/api/data/v9.1/new_accountbpfs?$select=activestageid,bpf_accountid,businessprocessflowinstanceid&$filter=bpf_accountid eq d2720425-53ad-43c3-b9dc-e7452b80ae13

Will cause the error:

In order to query this, we need to use the format:

https://carl123.crm.dynamics.com/api/data/v9.1/new_accountbpfs?$select=activestageid,bpf_accountid,businessprocessflowinstanceid&$filter=bpf_accountid/accountid eq d2720425-53ad-43c3-b9dc-e7452b80ae13

Where we’re appending to the lookup field the id name of what we’re querying.

This gives us the result we require:

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

Your email address will not be published. Required fields are marked *