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

Odata querry issue

$
0
0

Hi

I'm trying to retrieve two fields from the Billing Account of my Work Order form. Eventually i'll want to check for the value ap_Stopped and if it's equal to "All" then I'll show an Alert.

There's an issue with my "selectQuery" though so I was wondering if someone has an idea of what could be wrong? I'm trying to follow the example from this link: community.dynamics.com/.../javascript-odata-query

Thanks in advance!

    var lookupObject = Xrm.Page.getAttribute("msdyn_billingaccount");
	if (lookupObject != null)
	{
        var lookUpObjectValue = lookupObject.getValue();
        if ((lookUpObjectValue != null)) {
            var lookupid = lookUpObjectValue[0].id;
        }
    }
    var selectQuery = "/Account?&$filter=AccountId eq guid'" + lookupid + "'&$select=ap_Stopped, accountnumber";
	var oDataResult = null;
    //This is When my script fails
	oDataResult = MakeRequest(selectQuery);
	alert("Number = " + oDataResult[0].accountnumber + "\n" + "Stopped? = " + oDataResult[0].ap_Stopped);

Edit:

This is the "MakeRequest" function:

function MakeRequest(query) {
    var serverUrl = Xrm.Page.context.getClientUrl();
    var oDataEndpointUrl = serverUrl + "/api/data/v8.0/";
    oDataEndpointUrl += query;
    var service = GetRequestObject();
    if (service != null) {
        service.open("GET", oDataEndpointUrl, false);
        service.setRequestHeader("X-Requested-With", "XMLHttpRequest");
        service.setRequestHeader("Accept", "application/json, text/javascript, */*");
        service.send(null);
        var retrieved = JSON.parse(service.responseText).d;
        var results = new Array();
//Here is where my Script Stops running. for (var i = 0; i < retrieved.results.length; i++) { results.push(retrieved.results[i]); } // End for return results; } // End if return null; } // End function


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images