Hi All,
I am using the following code to retrieve and set a value on the record using Client WebAPI JS. The retrieved field is an option set and the returned value is a number. My question how do i get text instead of number.
function updatereqppr(executionContext){
debugger;
var formContext = executionContext.getFormContext();
if(formContext.getAttribute("iis_projectid").getValue()[0].entityType =="iis_project"){
var record_id=formContext.getAttribute("iis_projectid").getValue()[0].id;
Xrm.WebApi.retrieveRecord("iis_project",record_id,"?$select=iis_financing").then(
function get_pvalue(data){
var f_value = data["iis_financing"];
formContext.getAttribute("iis_financing@OData.Community.Display.V1.FormattedValue").setValue(f_value);
});
}
}
Hi , Vighnesh GVR
for get text on picklist field use "@OData.Community.Display.V1.FormattedValue" after your property name as
var f_value = data["iis_financing@OData.Community.Display.V1.FormattedValue"];
console.log(f_value);// picklist TextValue
https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/query-data-web-api
regards.
Hi partner,
After you get the value, you could use "Stringmaps" to get option set text by web api.
function updatereqppr(entityname, attributename, attributevalue) { debugger; Xrm.WebApi.retrieveRecord("stringmaps", record_id, "?$filter=objecttypecode eq '" + entityname + "' and attributename eq '" + attributename + "' and attributevalue eq '" + attributevalue).then( function get_pvalue(data) { if (results != null && results.value.length > 0) { var f_value = data.value[0].value; } }); }
In addition, I recommend to use Fetch Xml to get a lot more detail of option set.
Hope it helps.
Best Regards,
Leo
Sadly the webapi will only ever return the option set value as a number.
To access the text value of the option set you need to look at the metadata for the optionset.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,902 Super User 2024 Season 2
Martin Dráb 229,336 Most Valuable Professional
nmaenpaa 101,156