Getting Lookup Fields from Dynamics 365 Web API URL

Leave a comment

In Dynamics 365, we can use the Web API to return records through a web browser URL. In this post, we will look at how to get the lookup field data.

Let’s use Accounts as an example. We can access the API through the address https://yourorg.api.crm.dynamics.com/api/data/v9.1/:

We can then get accounts using https://yourorg.api.crm.dynamics.com/api/data/v9.1/accounts:

Now, accounts have a lookup field for Currency:

We can select the currency field through the Web API using https://yourorg.api.crm.dynamics.com/api/data/v9.1/accounts?$select=_transactioncurrencyid_value. However, this will only give us the Id of the Currency, not the name (e.g. US Dollar) or other fields:

To do this, we need to know the field details for the Transaction Currency field. Go to the field in Customizations. We can see the name transactioncurrencyid:

We can use https://yourorg.api.crm.dynamics.com/api/data/v9.1/accounts?$select=_transactioncurrencyid_value&$expand=transactioncurrencyid:

We can see this returns many fields for the transaction currency id. We can further filter this by https://yourorg.api.crm.dynamics.com/api/data/v9.1/accounts?$select=_transactioncurrencyid_value&$expand=transactioncurrencyid($select=currencyname):

Note if this doesn’t work and you get the message “cannot find a property named …”, try using the schema name, e.g. TransactionCurrencyId.

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 *