Hi,
You can use the expand in your query to retrieve the lookup field value from another entity using Xrm.Webapi. An example is shown below :-
//getting of userid from the context
var userId = Xrm.Utility.getGlobalContext().userSettings.userId.replace("{", "").replace("}", "");
//fetching user by id and expanding roles to get role names
Xrm.WebApi.retrieveRecord("systemuser", userId, "?$expand=systemuserroles_association($select=name)").then(
function success(result) {
//looping through all the roles available for user
for (var i = 0; i < result.systemuserroles_association.length; i++) {
//getting current role name
var roleName = result.systemuserroles_association[i]["name"];
}
},
function (error) {
Xrm.Navigation.openAlertDialog({ text: error.message });
}
Please mark the answer as verified if it is useful to you !!