I am back on the coding trail and struggling to get this javascript working:
function QuotePotentials(QuoteName) { var serverUrl = document.location.protocol + "//" + document.location.host + "/" + Xrm.Page.context.getOrgUniqueName(); var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/"; oDataEndpointUrl += "QuoteSet?$select=QuoteNumber,quote_details/sp_SellingProductId&$expand=quote_details&$filter=QuoteNumber eq '" + QuoteName + "'"; // oDataEndpointUrl += "QuoteSet?$select=quote_details/sp_SellingProductId&$expand=quote_details&$filter=QuoteNumber eq 'QUO-02084-M3Z0'"; var service = GetRequestObject(); if (service != null) { service.open("GET", oDataEndpointUrl, false); service.setRequestHeader("X-Requested-Width", "XMLHttpRequest"); service.setRequestHeader("Accept", "application/json, text/javascript, */*"); service.send(null); var requestResults = eval('(' + service.responseText + ')').d; alert(requestResults.results.length); if (requestResults != null && requestResults.results.length > 0) { var QuotePots = ""; for (var i = 0; i < requestResults.results.length; i++) { alert(requestResults.results[i]); var res = requestResults.results[i]; var resId = res.sp_SellingProductId; alert(resId); QuotePots = QuoteProdGroup(requestResults.results[i].sp_SellingProductId); } return QuotePots; } } return false; }
The first alert tells me the number of lines returned from the quote.
The second alert says [object Object].
The third alert says undefined.
Below is the Results (JSON) I get from using the OData Query Designer when I run it.
{"d" : {"results": [ {"__metadata": {"uri": "http://aserver/XRMServices/2011/OrganizationData.svc/QuoteSet(guid'4c9e3192-eaf6-e311-ba1a-02bf0a86f1e1')", "type": "Microsoft.Crm.Sdk.Data.Services.Quote" }, "quote_details": {"results": [ {"__metadata": {"uri": "http://aserver/XRMServices/2011/OrganizationData.svc/QuoteDetailSet(guid'3a1ea403-a268-4f93-94e9-49f89a10e600')", "type": "Microsoft.Crm.Sdk.Data.Services.QuoteDetail" }, "sp_SellingProductId": {"__metadata": {"type": "Microsoft.Crm.Sdk.Data.Services.EntityReference" }, "Id": "1ac1e0d9-9d8c-e211-a049-02bf0a86f1e1", "LogicalName": "product", "Name": "PPS200 c/w SLV" } } ] } } ] } }
I am trying to pull put the GUID for the product and then pass this to another function, but can't reference it.
Any help would be appreciated.
Matt