Reading field values in a view from a related entity using JavaScript

If you want to get access to the fields within a view, you will use this solution here:

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/customize/display-custom-icons-instead

This will give you access to the fields within your view. But its not exactly clear on how to read fields which belong to another entity.

I have added several fields from a related entity and you may find that when you debug your code, the fields will have a long alias name in front of the field like in the image below.

If I go into the ‘str‘ variable in the console, it will display all the values of the fields within your view.

To get access to the related field you will have to write out your code like this:

This is because the name of the variable has a period in the name and therefore cannot be retrieved normally.

Code for retrieving a field value belonging to another entity. (You will need to copy the alias value that your console displays when you are in debug mode.

var failuretime = str['a_5d7e1514d08ce811a961000d3a22c250.failuretime_Value'];

Code for retrieving a guid from a lookup field in V9 new UI. (This is different in the old UI)

var customerid = str.customerid_Value.id.guid

Hopefully this was useful! 🙂

One thought on “Reading field values in a view from a related entity using JavaScript

Leave a Reply

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