Querying Microsoft Dynamics Web Api - Trim column in Dynamics?

Viewed 47

I am querying Microsoft Dynamics (365) using the Web API. I have a scenario which I'm not sure is possible:

For example in Dynamics we have contacts with mobile numbers. Depending on how these have been entered in Dynamics, these may or may not contain spaces, as different people use different formats. For example one mobile number could be stored in Dynamics in multiple ways:

07900123456
07900 123456
07900 123 456

I need to query against this column.

In the web application I'm building, I can trim any spaces out of the values that users enter. However unless the mobile number stored in Dynamics contains no spaces then there will be no match using my current query:

var mobile = "07900123456";

var queryString = "contacts?" +
                "$select=contactid&" +
                $"$filter=mobilephone eq '{mobile}'";

var contact = await GetAsync(queryString);

In the above example, if a contact in Dynamics has this mobile number, but it contains a space in it, then it will not match.

Is it possible to modify this query, so I can trim out spaces in the mobile number column in Dynamics when running the query so there is a match?

1 Answers

Not possible (also with a like/contains operator), you should clean the data inside Dynamics so all the mobile phone numbers are stored in the same way (you can do it with a plugin for example)

Related