1

To bind my data on the mobile side it works like this :

getHeros() {
    this.wakanda.getCatalog().then(ds => {
        ds['Superhero'].query({orderBy:"ID desc",pageSize:3}).then(collection => {
            this.favoriteSuperheroes = collection.entities;
        });
    });
}

But like this I work directly on the table. I have a method who provide me everything I want on the server side. The Wakand's documentation tells me to do it like this:

ds.Company.myDataClassMethod().then(function (result) {

});

It won't work, I can't call my method, someone can help me ?

CoCoNours
  • 233
  • 1
  • 2
  • 13

1 Answers1

1

If the query() on the table works for you while calling dataclasss method does not. A possible cause is that your class method is not set to available to the public.

Please check whether the scope of the class method is set to "public". And test if your method can be accessed directly via REST: 127.0.0.1:8081/rest/Company/myDataClassMethod

Update: add type "any" to ds solves the problem. It appears

this.wakanda.getCatalog().then(ds:any => { 
    ds['Company'].myDataClassMethod().then(result => {
        //Work with Result Here
    }); 
 });
Xiang Liu
  • 393
  • 1
  • 7
  • Thanks for your reply. I can call my data class method on the backend, the scope is set to public and I can access directly via REST. I want to call that method on the mobile side, and I don't know the syntax. – CoCoNours Apr 25 '17 at 06:56
  • The syntax in your question seems correct to me. Did you get any return in "result" at all? – Xiang Liu Apr 25 '17 at 18:19
  • I try ds['Company'].method['myDataClassMethod'].then(function (result =>{ but it won't work. – CoCoNours Apr 25 '17 at 19:53
  • You had the syntax correct in your question. It should look like this: `this.wakanda.getCatalog().then(ds => { ds['Company'].myDataClassMethod().then(result => { }); });` – Xiang Liu Apr 26 '17 at 20:35
  • Thanks for the reply. Yeah, that's what I thought, but it doesn't work. I have the following message: "Property 'myDataClassMethod() does not exist on type 'DataClass'.". Yet this method exist and is a part of the DataClass Company, I can call it on the backend and it works, but not on the mobile side. – CoCoNours Apr 27 '17 at 07:34
  • I come to see in the little button help of wakanda's models, it tells: "A public on server datastore class method can be used only server-side.". So what I want to do is not achievable ? – CoCoNours Apr 28 '17 at 07:37
  • Since you can access myDataClassMethod() via REST, it should be public. However, just to be sure, can you check if you defined method scope to "public"? If not, please add this line after the method definition: `model.Company.methods.myDataClassMethod.scope = "public";` – Xiang Liu Apr 28 '17 at 17:17
  • Yeah the method scope is defined to "public". I can't edit my method locally (on Wakanda). Is this why I can't call my mobile side method ? How can I fix this ? – CoCoNours May 01 '17 at 19:25
  • Thats ok I find an solution just add ds:any like this: this.wakanda.getCatalog().then(ds:any => { ds['Company'].myDataClassMethod().then(result => { }); }); – CoCoNours May 02 '17 at 08:08
  • Interesting to see that is the solution. Looks like you can not call dataclass methods without specifying the type of ds in the callback. Were you able to do the query after adding ":any" ? – Xiang Liu May 02 '17 at 18:26
  • I try, and yes I am able to do the query after adding ":any". And I don't need the [''] anymore, ds.Company work instead of ds.['Company'] needed before. – CoCoNours May 03 '17 at 07:53