John Herdean
Posts: 0
Joined: Tue May 14, 2013 3:56 am

How to invoke a service in JS?

Hi,

WHat is the Appery line code in JS to invoke a service? For example,

-----------------------------------------------------------------

var a = localStorage.getItem('test')

if (a == 1 ) {
Appery.invokeservice('servicename');
}

--------------------------------------------------------------------

Im not sure if this line is correct: Appery.invokeservice('servicename');
please let me know whats the correct line code. Thanks

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How to invoke a service in JS?

Hi John,

Runcodeservicename.execute();/code
I would also recommend you to follow our tutorials on http://docs.appery.io

Dan Cuddeford
Posts: 0
Joined: Sat Aug 23, 2014 5:46 pm

How to invoke a service in JS?

Did this work? The docs
http://devcenter.appery.io/documentat...
note to use
serviceInstanceName.execute({});
but the service does not invoke when I call it via JS. If I invoke directly from a button it runs fine.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How to invoke a service in JS?

Dear Dan,

Could you please check whether you use codeservicename.execute();/code or codeservicename.execute({});/code?

Dan Cuddeford
Posts: 0
Joined: Sat Aug 23, 2014 5:46 pm

How to invoke a service in JS?

Hi sorry I tested again and servicename.execute(); works as expected

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How to invoke a service in JS?

Hi Dan,

Glad it's working.

Joe Cross
Posts: 0
Joined: Thu Oct 23, 2014 1:46 pm

How to invoke a service in JS?

How can I store the result in a JS variable? I'm using this but it errors out:

var results = servicename.execute();

The service response is structured like this. I really just want the "id" element.

{
"data":[
{
"name":"New Name",
"id":"10152361075586722",
"created_time":"2014-10-23T10:54:52+0000"
},
{
"name":"A Name",
"id":"347582686721",
"created_time":"2010-03-07T07:20:06+0000"
}
}

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How to invoke a service in JS?

Hi Joe,

Here is code how to handle response from JS:

pre

var onSuccess = function(data){
console.log(data);

Code: Select all

 var newData = data.data; 

 console.log("dataitems = " + newData.length); 

 //Iterate through data items: 
 for(var i = 0; i < newData&#46;length; i++){ 
    var id = newData[i]&#46;id; 
    alert("id[" + i + "] = " + id); 
 } 

};

servicename&#46;execute({success: onSuccess});

/pre

Regards.

Amith Reddy
Posts: 0
Joined: Wed Aug 06, 2014 5:48 am

How to invoke a service in JS?

how to pass the request value to the service while executing service using javascript

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How to invoke a service in JS?

Hi Amith,

1 "parameters" and "body" you can specify in any service you need.

2 It depends on server part how parameters should be passed.

3 here is correct code for better understanding it:

pre

dogsList2&#46;execute({
&#47;&#47;Specify url string parameters&#46; (works in all HTTP methods)
parameters: {"www": "aa"},
&#47;&#47;Specify body parameters&#46; (not supports by "GET" or "DELETE" methods, see RFC for details)&#46;
body: {"bdf": "123"}
})

/pre

Regards.

Return to “Issues”