cancel
Showing results for 
Search instead for 
Did you mean: 

How do I pass 'Parameter' to an entity set of a service in SAP MDK ?

rajeevparmar
Explorer
0 Kudos

when I open the oData service URL directly, I am able to access the data inside an entity by passing the required parameter as -

../odata/SAP/SERVICE_NAME/EntitySetName?$filter=Plant eq '1001'

This entity set doesn't return any result unless we pass the 'Plant' filter.

Now, when I do the same thing using SAP MDK, I am not getting data in my list picker. What I am doing is that I am using object binding for the list picker, and I am selecting the service, entity set and adding the same queryOption as above ($filter=Plant eq '1001') but it is not returning any data. Seems like this filter works only when the data is coming at first place. Since in my case, the entity set will send data only when we pass the plant filter, it is not returning any data, and as such this filter doesnt seem to be working.

I even tried to add this filter in query option in InitializeOffline.action but that seems to have no effect.

Can anyone help me understand how do I pass 'parameter' and not the filter to the oData service entity set so that I get back the data?

ManuelStampp
Advisor
Advisor
0 Kudos

Hi rajeevparmar,

as you mention the InitializeOffline.action, I'm assuming this is only targeting the offline case.

In case the OData producer only sends data when a parameter is set, it is essential that the parameter is added to the defining request in the InitializeOffline.action, as this defines the data set available for this MDK service. The graphical editor gives some hint how to assign these parameters to the defining request:

Given the fact that only synchronised data is accessible the controls (when using the same service), the filter on control/list level could be seen as optional in this case.

Make sure that the app is freshly initialised and synchronised after making this change.

Is this the way you tried it already?

rajeevparmar
Explorer
0 Kudos

Thanks for the response Manuel. I have already tried the steps mentioned by you above but that did not help. PFA the screenshots of the configs I did. Is there anything I am missing?

Initialise offline configs ->

Object binding for the list picker on the page ->

Regards,

Rajeev

Accepted Solutions (1)

Accepted Solutions (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

After making the change to the initialize offline action to add the filter have to reset your client to re-onboard to rebuild the offline database with the new parameter?

rajeevparmar
Explorer
0 Kudos

How do I do that? If you mean to reload the sap mobile client after clearing the cache, yes I did that. If you mean something else, could you please help me with the steps?

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

If your app has a logout action you can execute that to go back to the welcome screen. Or you can uninstall and reinstall the client from the app/play store to completely clear the offline database.

rajeevparmar
Explorer
0 Kudos

That I tried already but that did not help.

rajeevparmar
Explorer
0 Kudos

Your suggestion worked. I logged off and logged in back, and it worked. Thanks a lot.

alessio9119
Explorer
0 Kudos
Hi Bill,
I'm trying to build a rule where I take the value of a datePicker and pass it as a parameter to the backend. I'm new to MDK and I don't know how to build a rule I tried to use the .read but it gives me an error:   


thanks in advance.

former_member34
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi there,

You have a question and need help by the community? Instead of posting into an old question thread, it is more helpful for you, if you create your own question. Here is how to get started:

  1. Learn about asking and answering questions in SAP Community with this tutorial: https://developers.sap.com/tutorials/community-qa.html
  2. Ask your detailed question here: https://answers.sap.com/questions/ask.html
  3. Wait for a response.

That's it. Thank you!

Best regards

Your SAP Community moderator

Answers (1)

Answers (1)

dhanikawick41
Participant
0 Kudos

Hi rajeevparmar,

Firstly, could you please activate a trace in /n/iwfnd/traces (for your username) and see if the correct data is sent when you do the reset from the app. If the data is sent for the Plants, then we can assume that the request from MDK is correct and the data is sent to the local store correctly.

If this works without an issue, try to write a basic test rule in MDK to see if data is available for the plant you are passing.

var query = "$filter=Plant eq '1001'";
return context.read('/Services/yourservicename.service', 'EntitySetName', [], query).then(
	function (results) {		
		if (results && results.length > 0) {
			results.forEach(function (value) {
			alert(value.anypropertynameyouhave);
			}
			);
		}
	});
}

Ideally for you, one of these should not work. Try it and see where it is really failing.

Thank you.

rajeevparmar
Explorer
0 Kudos

It worked after logging off and logging in again. But I appreciate your effort in putting down the code to get the error issues if any.