Skip to main content

Notifications

Customer Service forum

WebAPI formatted values

Posted on by 1,942

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);
});
}
}

Categories:
  • PabloCRP Profile Picture
    PabloCRP 1,086 on at
    RE: WebAPI formatted values

    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.

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: WebAPI formatted values

    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.

    www.powerobjects.com/.../

    Hope it helps.
    Best Regards,
    Leo

  • Suggested answer
    Ben Thompson Profile Picture
    Ben Thompson 6,350 on at
    RE: WebAPI formatted values

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,902 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,336 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans