Retrieve xml childnode using Odata in dynamics CRM - odata

I've a problem when i try to pass a childnode attribute as a parameter using Odata in dynamics crm 2015!
for example:
when i pass a parentnode it works fine!
but when i pass a child node it does not work :
https://ServerURL/XRMServices/2011/OrganizationData.svc/InvoiceSet?$select=Name,InvoiceNumber,TotalAmount,TransactionCurrencyId&$filter=CustomerId/Name eq 'AttributeValue'
i also tried the "$expand" function but it doesn't work!
https://ServerURL/XRMServices/2011/OrganizationData.svc/InvoiceSet?$expand=Account_Invoice&$filter=Account/Name eq 'AttributeValue'
Your help will be greatly appreciated

Did you try using the OData Query designer?
You could build the query using the UI to make sure it works without wasting time messing with the OData query uri.
Also, please do not use the ServerUrl (assuming you are using .serverUrl()) on client side, always use the clientUrl() property. CRM might be deployed on a different machine name / url than the Url exposed via IIS.

Related

SAP OData Service Filter is not filtering

I'm learning to get delta data from SAP Fiori sample gateway to Azure SQL by using Azure Data Factory and filter feature on OData service.
I'm using OData Service that exposed by Fiori sample, and one of the table sample is PurchaseOrders.
I tried like this:
$filter=ChangedAt ge datetime '2020-09-08T22:00:00'
But it is still return all the records.
I found sap:filterable is false at metadata
Is that filterable false is made me cannot filter this?
Is there any other way to do delta extraction on OData rather than using filter?
Thank You
As #Boghyon wrote above the "sap:filterable" is just an Annotation, which can help to build the UI. You have to check the DPC_EXT class's GET_ENTITY_SET method of the entity type that you try to filter. If filtering isn't implemented then (1.) in case of standard service you're more or less stuck (it cannot be filtered for a reason) (2.) in case of custom service you can implement filtering

ADF - Odata - How to perform an optional select

I've created an ADF flow that loops over URL's to fetch OData using the OData connection.
However, not all fields are available in all URL's, there are certain ones that are available in one URL, but not in the other. A $Select is used to select the fields that we need.
Is it possible to have an optional selection (as in, if the path is not available, do not fetch this field and return null instead for instance)? Would help us a great deal.
I've tried adding ? after the field, but that does not work. $select=Field1,Field2,FieldOptional?
Thanks
As I understand you are trying to loop through a bunch of a URL and the query on the ODATA URL will change and so will be the fields . I think you can use a lookup where you pass the unique url and its gives the fields and then concatenate the url with the fields and make a odata call .

OData Model not loaded?

I am using an OData model in my SAP UI5 application. I do the following:
var oView = this.getView();
this._oModel = oView.getModel();
which I thought loaded the model and allowed me to access whatever I needed to inside the model. However whenever I try to get a property using getProperty(path) it returns undefined. I know the path is correct because I used it elsewhere in my application and it worked okay. The model I am using is named "metadata.xml" if that helps.
If you read the documentation provided by SAP talking about OData services (I assume v2), you might find your answer there. Since you are using getProperty(), "you can only access single entities and properties with these methods. To access entity sets, you can get the binding contexts of all read entities via a list binding." Therefore you may want to a read() of the entity set first and then use the results of this read to access whatever property you want.
Link to doc: https://sapui5.hana.ondemand.com/#docs/guide/6c47b2b39db9404582994070ec3d57a2.html

Passing parameters to an OData (GET) method which returns a collection

I am using OData v3. How do I pass a parameter to an OData controller and return a collection? Example of what I am trying to do:
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]
public IQueryable<ServiceInfoResult> Get([FromODataUri] int instanceId)
{
//etc
}
When I test this, I get this error:
No HTTP resource was found that matches the request URI 'http://localhost:30863/odata/ServiceInfoResultApi(1)'.
No action was found on the controller 'ServiceInfoResultApi' that matches the request.
I am aware of OData actions, but they are not a viable option on this case, because I need to get odata.count returned in the response, but no matter what I do, I cannot get that property returned when using OData actions (even when trying what was suggested here: Web API OData Inlinecount not working and here: Webapi odata expand with entity framework functions). So it would seem my only alternative was to create a new OData API controller for the ServiceInfoResult entity, so that I can avoid OData actions. However, as you can see above, passing in a parameter to a method that returns a collection seems to cause other errors.
Any solutions? And no, I can't update to OData v4, since that presents a whole host of other issues (it would take more time than I have and moreover, it doesn't support DateTime)
UPDATE
Thanks to #Fan Ouyang, I've discovered the reason for odata.count missing in the JSON payload is that I am not returning an entity type. If ServiceInfoResult were an entity in my database, odata.count would be returned. A bit silly that it's not being returned just because of that, but that's just how it is. I'm wondering if there's any workaround. For example, can I download the source code, change 1 line of code and use that? Otherwise, maybe it's time I started looking at OData v4. The project I have is quite big, so that's not a nice thought with the short amount of time I have. So, if there's any alternatives, I'd like to hear them. Thanks!
Try this sample, CheckoutMany method take parameter and return a collection https://github.com/OData/ODataSamples/tree/master/WebApi/v3/ODataActionsSample
Add [EnableQuery] attribute in the CheckOutMany action method, and add $inlinecount queryoption in requset url, you can see odata.count in payload
By the way, V4 support datetime now: http://odata.github.io/WebApi/#04-01-datetime-support
This was recently fixed with the release of version 5.7 (#odata.count is now returned for collections of complex types). More info here:
https://github.com/OData/WebApi/issues/484#issuecomment-153929767

Update object on PUT request using web api

In my web api, the PUT request is data bound using an interface like this public void Put([FromBody] IPage value), this works great but what is the best approach to update the object and put it back into my storage? Note that I'm using an interface here and the correct type is posted within the json using the $type attribute.
I'm also using RavenDB so putting the value straight into the document store does not work because the posted object is not associated with the current session.
Marcus,
Why can't you just call session.Store(value); ?

Resources