Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

formatted values are showing up as Undefined?!

$
0
0

I am using the Web API to retrieve formatted values from a related entity. I essential want the text value of each field to be put into one string separated by a hyphen. Here is the code I am using to do this: 

var req_b = new XMLHttpRequest();
        req_b.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contracts(064A66F9-96A7-E811-816A-480FCFE97E21)?$expand=contract_line_items($select=new_locationgrouping,new_servinggroup,new_servingtime)", true);
        req_b.setRequestHeader("OData-MaxVersion", "4.0");
        req_b.setRequestHeader("OData-Version", "4.0");
        req_b.setRequestHeader("Accept", "application/json");
        req_b.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req_b.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
        req_b.onreadystatechange = function () {
            if (this.readyState === 4) {
                req_b.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(this.response);
                    var contractid = result["contractid"];
                    for (var a = 0; a < result.contract_line_items.length; a++) {
                        var locationdestination = result.contract_line_items[a]["new_locationdestination"];
                        var servinggroup = result.contract_line_items[a]["new_servinggroup"];
                        var servinggroup_formatted = result.contract_line_items[a]["new_servinggroup@OData.Community.Display.V1.FormattedValue"];
                        var servingtime = result.contract_line_items[a]["new_servingtime"];
                        var servingtime_formatted = result.contract_line_items[a]["new_servingtime@OData.Community.Display.V1.FormattedValue"];

                        var optionValue = 100000000 + a;
                        var optionText = servinggroup_formatted + "-" + servingtime_formatted + "-" + locationdestination; 

                        Xrm.Page.getControl("new_contractserving").addOption({ value: optionValue, text: optionText });
                    }
                } else {
                    Xrm.Utility.alertDialog(this.statusText);
                }
            }
        };
        req_b.send();


For some reason I am getting: "undefined-undefined-undefined" in the new_contractserving field. What is going on here? I just want the text value of servinggroup and servingtime (which are options sets) along with locationdestination (which is a text field). Why am I getting undefined?!


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images