In Power Pages, we often work with Dataverse tables that are related to each other using lookup columns. When building dynamic pages, we may need to retrieve data from these lookup columns using Web API and JavaScript.
This article explains how to access lookup column data using Web API with a simple and practical example. We will retrieve Dealer records from the Dealer table and related Machine records from the Dealer Machines table.
Tables used in Example
I have created the following two Dataverse tables:
1 - Dealer Table
This table stores dealer information

2 - Dealer Machine Table
This table stores machine details and contains a lookup column (Dealer) to the Dealer table.

Understanding Relationship between Tables
The Dealer column in the Dealer Machines table is a lookup column.
This lookup creates a many-to-one relationship
One Dealer can have multiple Machines
Javascript Code Example
Below is the wrapper code that will be used for all Web API calls in this article. (put it on top of Javascript file)
(function (webapi, $) {
function safeAjax(ajaxOptions) {
var deferredAjax = $.Deferred();
shell.getTokenDeferred().done(function (token) {
if (!ajaxOptions.headers) {
$.extend(ajaxOptions, {
headers: {
"__RequestVerificationToken": token
}
});
} else {
ajaxOptions.headers["__RequestVerificationToken"] = token;
}
$.ajax(ajaxOptions).done(function (data, textStatus, jqXHR) {
validateLoginSession(data, textStatus, jqXHR, deferredAjax.resolve);
}).fail(deferredAjax.reject);
}).fail(function () {
deferredAjax.rejectWith(this, arguments);
});
return deferredAjax.promise();
}
webapi.safeAjax = safeAjax;
})(window.webapi = window.webapi || {}, jQuery)Web API Wrapper Function in Power Pages
In Power Pages, we cannot directly call the Dataverse Web API using a normal AJAX request. Every Web API call must include a request verification token to ensure the request is secure and comes from an authenticated user.
To make this easier, we use a wrapper function called safeAjax.
This wrapper automatically:
Gets the security token
Adds it to the request headers
Handles authentication validation
Executes the Web API call safely





Join the conversation! Your thoughts help the community grow.