Skip to Content
Author's profile photo Gopal Anand

Getting annotations driectly from server

Introduction

The oData annotations that tell which of the OData properties contain e.g. a phone number, a part of a name or address, or something related to a calendar event or an analytic query. This is important for apps running on mobile devices that want to seamlessly integrate into contacts, calendar, and telephony.

In the last blog, I wrote how to create annotations and consume it in a Fiori application.

When we made our application, it created a local reference for our annotations and the next time when we run our application, the local copy of annotations is called and the view is rendered per it.

This is how our application structure looks like:

Here we can see the local service with the metadata.xml which holds the annotation properties.

Well how the local metadata is accessed. Let’s have a look at the maniest.json

Here in the above picture, we can see the uri of odata service , and then in settings we can see the uri of local service that is referring to the metadata.xml

But we can see two things.

The metadata is dependent on the service it is bound to.

If there is change in odata , the local metadata is still the same and thus won’t reflect any change in UI.

In a case where there is change in service pack and we need to change our annotations or the odata , shall we go back to the application and regenerate the metadata , or what if we have the ability to get our annotations from another server and then render it with odata coming from some other server .

In this blog, will make our application independent. No need to depend on local service to get annotations.

Steps :

Go to manifest.josn, Add the following setting to it and you will be good to go with annotations coming separately from OData service or from a different service url.

"dataSources": {
			"mainService": {
                       // service uri
				"uri": "/sap/opu/odata/sap/ZANNOTATIONS_BLOG_SRV/",
				"type": "OData",
				
				"settings": {
                        // telling that we are getting annotations from "from Server"
					"annotations" : ["fromServer"]
				}
			},
                      //specifying the annoations settings
			"fromServer" :{
                     // annoations uri , we can see its coming from different project
				"uri" : "/sap/opu/odata/SAP/ZANNOTATIONS_SRV_04/$metadata",
                     // telling that it is a odata annotaiton
				"type": "ODataAnnotation"
			}
		},

and we are done.

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Vinayak Khosla
      Vinayak Khosla

      Hi Gopal,

      Very nice blog, Can I use the direct annotation link also, I have created one standalone annotation in SEGW, using Annotation Model for Referenced Service

      So I can find my annotation here:

      source:

      /sap/opu/odata/IWFND/CATALOGSERVICE;v=2/Annotations(TechnicalName=’annotation_name’,Version=’0001′)/$value

      Can I use this source in the “uri”

      "fromServer" :{
                           // annoations uri , using direct link
      				"uri" : "direct_link",
                           // is this type is valid if we use direct link
      				"type": "ODataAnnotation"
      			}

       

      Author's profile photo Gopal Anand
      Gopal Anand
      Blog Post Author

      Hi Vinayak,

      As per my knowledge you cannot use direct URI in manifest , it will be blocked as a mixed content. with following response : 

      if You set the destination properly in neo-app.json and provide the uri like the one given in above example it will work fine.

       

      Till now i don't know how to use direct links . If i get a solution I will update you.

      Best Regards

      Gopal Anand

       

      Author's profile photo Vinayak Khosla
      Vinayak Khosla

      Thanks Gopal.

      Author's profile photo Lars Bregnedal
      Lars Bregnedal

      Hi

      Do anybody knows how to change the call the oData service "onInit" ?

      So that the ListReport will start up with data - and the end-user don't need to call the "go" button to get data to the screen ?

       

      Thanks

      Lars

      Author's profile photo Gopal Anand
      Gopal Anand
      Blog Post Author

      Hi  Bregnedal ,

      I can't understand properly what you asked, Can you provide some code snippet.

      As much as i can understand you need to make call inside on init and add onRequestCompleted.