Hello,
Thank you so much for this. This scenario is similar to mine where I am trying to show Product description instead of Product ID (Unique Identifier) field. I tried using the same code but I don't see anything happening, no errors and the functionality is not working as well.
This is my code. I have created a lookup for choosing Product within the 'Services' table. I want the Product lookup to show the display name from description field instead of product number.
Lookup Name : m***_product
Unique identifier of Product table - productnumber (Product table)
the field value that needs to be shown. - description (Product table)
var sdk = window.sdk || {};
(function (setProductDisplayName) {
"use strict"
this.setProductDisplayName = async function (executionContext) {
const formContext = executionContext.getFormContext();
let productColumn = formContext.getAttribute("productnumber");
let productValue = (productColumn === null) ? null : productColumn.getValue();
if (productValue !== null) {
let productnumber = productValue[0].id.replace(/{|}/g, "");
await Xrm.WebApi.retrieveRecord("product", productnumber).then(
function success(result) {
if (productValue[0].name === result["name"]) {
productValue[0].name = `${result["description"]}`
productColumn.setValue(productValue);
}
},
function (error) {
console.log(error.message);
}
);
}
}
}).call(sdk);