Roger6240907
Posts: 0
Joined: Mon Sep 16, 2013 5:33 pm

Execute service not assigned to a specific page?

I want to track user interactions by using mixpanel. It provides JSON APIs that I can call successfully if I encode the request in base64. This requires a little bit of JS code I added as JS asset.
What I would like to do is to have a simple function log() that I can call whenever I wants.

At the moment I can do that within one page where I added a service call MX_track and I trigger it with MX_track.execute({});

Unfortunately I can not add the same service with the same name to another page, hence I cannot use the JS function log() over multiple pages.
In theory if a service only needs to access localStorage it should be possible to be triggered anywhere regardless if it is added to a page or not. I tried to create a template, but the service does not propagate to the child pages.
Is there any other way?

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

Execute service not assigned to a specific page?

Hi Roger,

For each page, create its own datasource, based on a service. You can not use the same datasource on different pages, as each has certain mapping for a specific page.

In your example the datasource call is:preMX_track.execute({});/pre

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

Execute service not assigned to a specific page?

Reference to similar topic: https://getsatisfaction.com/apperyio/...

Hi gang,

This isn't a question or a problem: just a suggestion.

I too have run into the same difficulty that Roger and Janko encountered.

In my case, I have a Javascript function that is available across my entire app (which is comprised of several pages). The function should (ideally) call a singular service, but I can't do that.

I make use of an identical Appery server code service on all pages and I'm using the xyz.execute(); service to call my server code. I find it inconvenient to have to edit mappings on every single page for what is essentially the same identical service.

It would be nice to be able to call on a page's service from another page (without having to do workaround like navigating back and forth to pages and so forth).

Of course, I'm suggesting this with full knowledge that perhaps something does, in fact, meet my needs.

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

Execute service not assigned to a specific page?

Hello!

I'm sorry for taking too long to reply...
If you need to call service which is on one screen from different screens and at the same time have this service mapping working, it would work only if your pages are rendered in one html file (otherwise pages are replaced and there is nowhere to perform mapping)
1) Check Render all pages in one html file
2) Before service invocation ensure service is loaded. It is loaded after pre screenName_js();/pre is executed
where screenName - screen name which contains service.
For example use the following code:pre if( typeof(restserviceName) === 'undefined') {
screenName_js();
}
restserviceName.execute();/preIf you don't need mapping, but want to perform any actions on server response, there is no need to render all pages in one html file, you can define service manually in global scope. Here is more information https://getsatisfaction.com/apperyio/...

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

Execute service not assigned to a specific page?

Thanks Maryna!

Jamie

Sam6522984
Posts: 0
Joined: Thu Dec 26, 2013 2:35 pm

Execute service not assigned to a specific page?

Hi

I solved this problem with defining the services on the startpage, then I just start the service with the execution-method. I think this approach will only work if you don't map the response to the page.

Maybe an official can explain possible problems with this approach.

Sam

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Execute service not assigned to a specific page?

Hi,

Here is two things in appery:

1 service

2 datasource - derivative of service.

Service - global to all pages.

Datasource available after page has been initialized.

In case when all pages generates in the one page - your all datasource are available from all pages.

In case when you use separate pages your datasources available only within the initialized pages.

But if you want to use separate pages and use services, you cancreate datasource dynamically.

See following code to understand how do it:

pre
//Create dataSource.
//note "ToDoDB_users_list_service" - is service and should be replaced by yours one.
var yourDataSource = new Apperyio.DataSource(ToDoDB_users_list_service, {
'onBeforeSend': function(jqXHR) {

Code: Select all

 }, 

 //onComplete eventHandler 
 'onComplete': function(jqXHR, textStatus) { 
     console.log("complete"); 
 }, 

 //onSuccess eventHandler 
 'onSuccess': function(data) { 
     console.log("success"); 
 }, 

 //Error eventHandler 
 'onError': function(jqXHR, textStatus, errorThrown) {}, 

 'responseMapping': [], 

 'requestMapping': [{ 
     'PATH': ['X-Appery-Database-Id'], 
     'TYPE': 'STRING', 
     'HEADER': true, 
     'ATTR': '{database_id}' 
 }] 

});

yourDataSource.execute();
/pre

Sam6522984
Posts: 0
Joined: Thu Dec 26, 2013 2:35 pm

Execute service not assigned to a specific page?

Thank you for the clarification.

So as long as I don't map a service to HTML-components, I can use them on every page? Also the service should be defined in the startpage.

This is currently my approach for services, which I need on multiple pages. I'm a bit concerned that this could stop working.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Execute service not assigned to a specific page?

Hi Sam,

Yes, you can call datasources in all pages, if it defined in already inited page (for example start page or if you have this option: http://prntscr.com/3ctop9/direct ).

Also you can create datasource dynamically with code described in Igors message.

Don't worry, if you have this option http://prntscr.com/3ctop9/direct your services could not stop to work.

Also, if you can migrate between these two ways, if it would need.

Regards.

Sam6522984
Posts: 0
Joined: Thu Dec 26, 2013 2:35 pm

Execute service not assigned to a specific page?

Thank you for the quick response and the clarification.

Return to “Issues”