Wednesday, 22 May 2019

Retrieve Local Option set metadata in java script using webapi, Dynamic 365

   function GetOptionSetOptionValue(optionText, optionSetLogicalName)
{
        debugger;
        var req = new XMLHttpRequest();
        req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/EntityDefinitions(LogicalName='ab_bid')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq '" + optionSetLogicalName + "' &$expand=OptionSet", false);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
        req.send(null);
        if (req.readyState === 4) {
            req.onreadystatechange = null;
            if (req.status === 200) {
                var results = JSON.parse(req.response);
                debugger;
                for (var i = 0; i < results.value[0].OptionSet.Options.length; i++) {
                    debugger;
                    var Label = results.value[0].OptionSet.Options[i].Label.UserLocalizedLabel.Label;
                    if (Label.trim().toLowerCase() == optionText.trim().toLowerCase()) {
                        return results.value[0].OptionSet.Options[i].Value;
                    }
                    //alert(Label);
                }
            } else {
                Xrm.Utility.alertDialog(req.statusText);
            }
        }
    }

No comments:

Post a Comment

Read only field , get latest value from read only field in in power app portal

Below line is used to make field readonly in power app portal through js $( "#bdo_relationshiprole_name" ).parent().css( "po...