async function loadDropdownFromDataverse({table,column,dropdownId,filter = ""}) {
try {
let apiURL = `${siteURL}/_api/${table}?$select=${column}`;
if(filter){
apiURL += `&$filter=${filter}`;
}
window.portalLanguage = "{{ website.selected_language.code }}";
const data = await safeAjax({
url: apiURL,
type: "GET",
contentType: "application/json",
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Prefer": 'odata.include-annotations="Microsoft.Dynamics.CRM.localizedlabels"',
"Accept-Language": window.portalLanguage
}
});
const dropdownMenu = document.querySelector(`#${dropdownId}`);
dropdownMenu.innerHTML = "";
const valueMap = new Map();
if(data && data.value){
data.value.forEach(record => {
const displayValue =
record[`${column}@OData.Community.Display.V1.FormattedValue`] ||
record[column];
const rawValue = record[column];
if(displayValue && !valueMap.has(displayValue)){
valueMap.set(displayValue, rawValue);
}
})
}
valueMap.forEach((rawValue, displayValue) => {
let li = document.createElement("li");
let link = document.createElement("a");
link.className = "dropdown-item";
link.href = "#";
link.textContent = displayValue;
link.dataset.value = rawValue;
li.appendChild(link);
dropdownMenu.appendChild(li);
});
} catch(error) {
console.error(`Error loading dropdown for ${column}`, error);
}
}
I checked the request through Inspect > Network tab :
fetch("https://customer-portal-dev.powerappsportals.com/_api/gun_articleses?$select=gun_articlestatus", {
"headers": {
"__requestverificationtoken": "*********************",
"accept": "*/*",
"accept-language": "de-DE",
"cache-control": "no-cache",
"content-type": "application/json",
"odata-maxversion": "4.0",
"odata-version": "4.0",
"pragma": "no-cache",
"prefer": "odata.include-annotations=\"Microsoft.Dynamics.CRM.localizedlabels\"",
"priority": "u=1, i",
"request-id": "************************",
"sec-ch-ua": "\"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"150\", \"Microsoft Edge\";v=\"150\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"traceparent": "************************************",
"x-requested-with": "XMLHttpRequest"
},
"referrer": "https://customer-portal-dev.powerappsportals.com/de-DE/page/",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
});
In the response the object I recieved is -
{
"@odata.etag": "W/\"1656075947\"",
"gun_articlesid": "86d042fc-7f5d-f111-a826-000d3a4b827d",
"gun_articlestatus@OData.Community.Display.V1.FormattedValue": "Published",
"gun_articlestatus": 221540000
}
In the CRmTranslations.xml , There exists the German translation for 'Published' in the gun_articleses entity.