I'm trying to query the Opportunity set, and I have a custom lookup field on the opportunity form that I'm trying to get the value of (either the guid or the name - preferably the name). However, I'm having trouble writing the expand part of it, as I haven't used that command before. Here's what I have so far:
var ODATA_EntityCollection = "/OpportunitySet"; var urlQuery = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection; urlQuery += "?$select=new_Type,new_Date,new_Category,OpportunityId,new_opportunity_Agent&$expand=new_opportunity_Agent&$filter=CustomerId/Id eq (guid'" + contactId + "') and StatusCode/Value eq 1&$orderby=new_Date asc"; var req = new XMLHttpRequest(); req.open("GET", urlQuery, false); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.send(null); var returned = eval('(' + req.responseText + ')').d; var results = returned.results; alert("This doesn't show up"); if (results == null || (results != null && results.length == 0)) return null; return results;
It doesn't get to the alert. Any ideas?
This was working fine before I tried the expand.
Thanks.
*This post is locked for comments
Thanks for that. I imported the solution, but I don't get anything in the 'Primary Entity' drop down. It looks like it's not working for me.
It works with the expand. I get back 1 result. It's not in xml format, just an RSS feed.
Are you using this tool:
it could help you to get the right query and JS Syntax.
Secondly I would debug to this line:
var returned = eval('(' + req.responseText + ')').d;
I doubt this works correct.
Does the URL work in the browser without the expand part?
Hi,
did you try to debug? At least you might add an "alert" right after send to see what's returned from the server.. I'm wondering if this is because of the synchronous Http request, although, since you are on 2011.. it's probably and older version of IE anyway, so should be supported..
Thanks for your reply. I have checked the relationship name, and it is correct. I also copied the URL into a browser and that also works. Is the construction of the rest of the code ok?
Check the relationship name is valid and in proper casing(new_opportunity_Agent), that might solve the issue. The better way is to hit the url in browser and test before proceeding to JS.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,219 Super User 2024 Season 2
Martin Dráb 230,056 Most Valuable Professional
nmaenpaa 101,156