web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

OData Select error - can someone tell me what's wrong here?

(0) ShareShare
ReportReport
Posted on by

I'm trying to pull the price of a product based on the default price list of an order.

var odataSelect = _getServerUrl() + "ProductSet?$select=product_price_levels/Amount/pricelevelid&$expand=product_price_levels&$filter=pricelevelid eq guid'" + pricelist +"' and ProductId eq guid'" + packageGUID + "'";
     
alert(odataSelect);

Why am I getting this error? 

3288.error2.png

*This post is locked for comments

I have the same question (0)
  • fishyjj Profile Picture
    on at

    When you go to that URL in your browser, what does it say the error is?

  • Community Member Profile Picture
    on at
    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    "); vertical-align: bottom; height: 10px;"><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <code/>
    "); vertical-align: bottom; height: 10px;"><message xml:lang="en-US">
    Query options $expand, $filter, $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource.
    </message>
    </error>
  • Suggested answer
    pavanmanideep Profile Picture
    1,331 on at

    Hi Tek,

    If you were using 2011 version, then only you should be using getServerUrl() as it was deprecated in 2013 and later versions(else you should be  using getClientUrl). One more catch here, while you were selecting an entity to retrieve data using its data set, you should use a forward slash(/) like

    var odataSelect = _getServerUrl() + "/ProductSet?$select=product_price_levels/Amount/pricelevelid&$expand=product_price_levels&$filter=pricelevelid eq guid'" +

    instead of 

    var odataSelect = _getServerUrl() + "ProductSet?$select=product_price_levels/Amount/pricelevelid&$expand=product_price_levels&$filter=pricelevelid eq guid'" + pricelist +"' and ProductId eq guid'" + packageGUID + "'";
       
    You can refer to to the below post for some better idea about the exact syntax. Hope you were using ODATA Query designer to get the rest of the query.

    https://garethtuckercrm.com/2011/02/22/adding-selection-criteria-to-rest-queries/

    https://debajmecrm.com/2014/10/31/error-with-xrm-page-context-getserverurl-in-crm-2015/ 

    Hope it helps

    Thanks

  • Community Member Profile Picture
    on at

    thanks we are on crm online 2016, what should i be using?

  • Suggested answer
    pavanmanideep Profile Picture
    1,331 on at

    Changing the code to use Xrm.Page.context.getClientUrl(); would work here..

  • Community Member Profile Picture
    on at

    Well if you look closely at the odataSelect code, the _getServerURL() is a function call and here's the return code. It is using the getClientURL(). The issue is more syntax related for my example.

    function _getServerUrl() {
        
        var OrgServicePath = "/XRMServices/2011/OrganizationData.svc/";
        var serverUrl = "";
        if (typeof GetGlobalContext == "function") {
            var context = GetGlobalContext();
            serverUrl = context.getClientUrl();
        }
        else {
            if (typeof Xrm.Page.context == "object") {
                serverUrl = Xrm.Page.context.getClientUrl();
            }
            else
            { throw new Error("Unable to access the server URL"); }
        }
        if (serverUrl.match(/\/$/)) {
            serverUrl = serverUrl.substring(0, serverUrl.length - 1);
        }
        return serverUrl + OrgServicePath;
    }
    
    


  • Suggested answer
    pavanmanideep Profile Picture
    1,331 on at

    Modify the code like this

    function _getServerUrl() {

       var OrgServicePath = "/XRMServices/2011/OrganizationData.svc/";

       var serverUrl = 'Keep single quotes here';

       if (typeof GetGlobalContext == "function") {

           var context = GetGlobalContext();

           serverUrl = context.getClientUrl();

       }

       else {

           if (typeof Xrm.Page.context == "object") {

               serverUrl = Xrm.Page.context.getClientUrl();

           }

           else

           { throw new Error("Unable to access the server URL"); }

       }

       if (serverUrl.match(/\/$/)) {

           serverUrl = serverUrl.substring(0, serverUrl.length - 1);

       }

       return serverUrl + OrgServicePath;

    }

    Code seems to be fine, if you were still facing similar issues, modify the syntax as appropriate as per 

    https://msdn.microsoft.com/en-us/library/mt742431.aspx#bkmk_codeSample 

  • Community Member Profile Picture
    on at

    That didnt work, must be syntax in the other parts of the code

  • Verified answer
    tw0sh3ds Profile Picture
    5,600 on at

    Hi,

    If you have id of pricelist and id of product than you are querying bad set:

    ProductPriceLevelSet?$select=Amount&$filter=ProductId/Id eq (guid'XXXXXXX') and PriceLevelId/Id eq (guid'YYYYYYYY')

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans