Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Provide Web service without measures with Datasource SDK

Hi folks,

i am trying to build a datasource that get connected to a custom Web service. Its a restful service that supply the following data in JSON format:

[{"webapp": "app", "scope": "IT", "feeder": "heise IT", "identifier": "id234", "news": "this is a text"},

{"webapp": "app", "scope": "IT", "feeder": "golem", "identifier": "id567", "news": "this is another text"}]

It contains no measure (hope i am correct) and i am not able to find some informations in the developers guide and the scn.

Question 1: In my opinion it is right to create a datasource component to collect data from any Web service. Is that true in my case?

My first problem was to implement the "defineDimension()" method from the sap.designstudio.sdk.DataBuffer.subclass("...") { ... } class. I try to use just colums and set the "containsMeasure" option to the field with the highest granularity, the "news".

Question 2: Could it be that numeric measure(s) are mandatory? I try to use the method and the "fillWithArray() function, but without success.

After that i decided to clean the "defineDimension()" methode and hold the Web service data in my own javascript object and add some methods to the contributions.ztl to get 1 specified unique news text back.

The result should be:

DS_1.getNewsByIdentifier("id234") -> "this is a text"

I try to solve it with the hack from Michael Howles (Design Studio 1.3 SDK - Are script contributions for SAPUI5 method functions supported?), but i cant achieve it.

My component.js looks like this:

sap.designstudio.sdk.DataBuffer.subclass("...", function() {

var that = this;

var _execute;

var _allNews = [];

var _news = null;

.....

this.init = function() {

//empty

  };

// Getter/Setter

this.execute = function(value) {

  if (value === undefined) {

  return _execute;

  } else {

  _execute = value;

  return this;

  }

  };

  this.news = function(value) {

  if (value === undefined) {

  return _news;

  } else {

  _news = value;

  return this;

  }

  };

.....

this.afterUpdate = function() {

$.ajax({

  async: false,

  crossDomain: true,

  url: _url,

  headers: {

  'Authorization': "Basic " + btoa(_user + ":" + _pw)

  }

  }).done(function(dataArray) {

  _allNews = dataArray;

  that.fireUpdate(true);

  });

  // Test

  this.news = x.setExecute(_execute);

  alert("Test:" + this.news);

  that.firePropertiesChanged(["news"]); // brings an error

}

var x = {

  getNewsById : function(value) {

  alert("I am 'getNewsById'.  You passed me value: " + value);

  return _.find(_allNews, function(y) {

         return y.identifier == value;

     }).news;

  },

  setExecute : function(s){

  var cmd;

  if(s) cmd = s.split("~");

  if(cmd!==undefined && cmd.length > 1){

  var methodNameParam = cmd[0].split("|");

  var methodName = methodNameParam[0];

  var methodParam;

  if(methodNameParam.length>1) methodParam = methodNameParam[1];

  if(this[methodName]) {

  return this[methodName](methodParam);

  } else {

  alert("You passed me a bad method (" + methodName + ")");

  }

  }

  },

  getExecute : function() {

  return String(Math.random());

  }

  };

});

In my contribute.ztl the code looks like this:

class .... extends SdkDataBuffer {

  // needed to inherit parent class methods

....

  /* Returns a specific news by Identifier */

  String getNews(String someId) {*

  this.execute = "getNewsById|" + someId + "~" + Math.random();

  return this.news;

  *}

}

Conribution.xml

<property id="news" title="Kommentar" type="String" group="Webservice" visible="true"/>

Now its the problem in my case that the method dont return any String. But "this.news" contains the necessary String "this is a text"!!

DS_1.getNewsById("id234") -> ""

I believe that the "Getter/Setter" just called one time and not afterwards to get this.news. In have read in the SDK guideline that it is possible to force an update of any property from the contribution.xml with "firePropertiesChanged":

this.comment = x.setExecute(_execute); // work!

that.firePropertiesChanged(["news"]);

But just an error come up:

Without "that.firePropertiesChanges(["news"]) the method call DS_1.getNewsById("id234") never retuns any value.

Question 3: How can i return the actual this.news content?

I am proud for any help or hint to solve this issue

Best regards,

Jens

Former Member
Not what you were looking for? View more on this topic or Ask a question