w
Posts: 0
Joined: Tue Mar 26, 2013 12:30 pm

Pass request parameter or any parameter with a service.execute({}) ?

Can I pass a variable or request parameter with the service.execute({}) method, so that I can use this variable in the service mappings?

For example service.execute({ param1="1"}); or something like that?

Because I have a for-loop which executes a service multiple times, but each time with a different request parameter value.

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

Pass request parameter or any parameter with a service.execute({}) ?

Hi,

Yes, you can pass an object with a set of parameters as an argument. It should have the following structure:
code{
data: { object with request params },
headers: { object with request header params }
}/code
This parameter extends parameters sent by default builder settingsе. That is, you can change only one setting - there is no need to list every time all the request parameters added through the builder.

Please notice it's just an opportunity that should not be used without the knowledge of the issue.

w
Posts: 0
Joined: Tue Mar 26, 2013 12:30 pm

Pass request parameter or any parameter with a service.execute({}) ?

Can I use these extended request params in the service success event also?

My goal is to 'label' a service.execute execution. So I have a for-loop:

precode
for (var counter=0; counter < x&#46;length; counter++){

Code: Select all

service&#46;execute({  
       data:  {   
               "executionNumber": counter   
       }      
}); 

}

/code/pre

So the goal is now that this "executionNumber" is available to the service SUCCESS event, so the service success event knows which iteration the service call was.

Note that I can not change the service itself, to just add this request parameter in its service response, because the service response parameters are fixed because the online service is not under my control.

So maybe my approach to add a request parameter to the service is wrong, because the server expects a fixed request parameter pattern.

Do you have a solution to "add" some data to a service execution, that can be used in the success event?
I can't do it with a localstorage variable, because the localstorage variable would be overwritten by the next iteration of the for-loop BEFORE the service response of the first iteration was completed. So then the service success event would get a wrong localstorage variable. (because of asynchronity of ajax calls)

A solution could be to "overwrite" the success callback function, and add a parameter to this function! Can this be done with the service.execute call? For example:

precode
service&#46;execute({
data: {
success: function(data, MYPARAMETER) { &#46;&#46;&#46; }
}

})
/code/pre

w
Posts: 0
Joined: Tue Mar 26, 2013 12:30 pm

Pass request parameter or any parameter with a service.execute({}) ?

Yes, but all examples for deferred objects work with the direct ajax calls, which are made transparent by Appery by the custom Appery service.execute({}) call.

The end goal is that each service.execute({}) call in the for loop is executed only when the one before has finished (in essence: has finished its complete or success event).
Could you give a concrete example how I could use the deferred object with service.execute calls in a for-loop?

I am sure that a lot of Appery users will have this same type of question now or in the future.

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

Pass request parameter or any parameter with a service.execute({}) ?

Besides code {
data: {},
header: {}
}/codeyou can send success and complete callbacks as a parameters. But they will replace the values in builder.

Also you can use global variables.

Rommel Paras
Posts: 0
Joined: Fri Jun 14, 2013 2:58 am

Pass request parameter or any parameter with a service.execute({}) ?

Can I skip headers if I don't know what to put in there?

What about object with request params - how do I declare it?

service.execute({data:{person}}) where person is an object, e.g.

person=new Object();
person.firstname="John";
person.lastname="Doe";
person.age=50;
person.eyecolor="blue";

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Pass request parameter or any parameter with a service.execute({}) ?

I'm assuming you are invoking your service -- so you can specify any parameters you want/need. You can specify objects using JSON format.

Jamie5245261
Posts: 0
Joined: Thu Feb 20, 2014 2:01 pm

Pass request parameter or any parameter with a service.execute({}) ?

Katya wrote:

[quote:]
...Also, you can use global variables...
[/quote]

Could you discuss this further or point to existing tutorials or documentation? I'm actually looking to find out how to use global variables in my appery app. When I use the term "global", I mean across the entire app.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Pass request parameter or any parameter with a service.execute({}) ?

Hello!
[quote:]how to use global variables in my appery app[/quote] means global variables in JS, here is more information https://developer.mozilla.org/en-US/d...

Return to “Issues”