How to call mapping with JS

This forum contains topics that were moved from Get Satisfaction
Sami
Posts: 0
Joined: Mon Jun 29, 2015 9:24 pm

How to call mapping with JS

Post by Sami »

Hello,

It is possible to call a mapping using JS the same way we call a service with servicename.execute() ??

Image

Pavel Zarudniy
Posts: 0
Joined: Mon Jul 06, 2015 8:56 am

How to call mapping with JS

Post by Pavel Zarudniy »

Hi Sami,
It is possible... but it is not good practice to call mapping from JS.

You need to call Apperyio.processMappingAction function with stucture that describe your mapping for example:
code
{
"homeScreen": "startScreen",
"directions": [

Code: Select all

     { 
         "from_name": "startScreen", 
         "from_type": "UI", 

         "to_name": "storage", 
         "to_type": "LOCAL_STORAGE", 

         "mappings": [ 

         { 

             "source": "$['mobiletextinput_15:text']", 
             "target": "$" 

         } 

         ] 
     } 

     ] 
 } 

/code
For more info you can look at the source code some project with mapping

Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

How to call mapping with JS

Post by Jack Bua »

I think I understand all of that code except for:

"homeScreen": "startScreen",
"directions":

1) Is "homeScreen" always going to be "homescreen"?
2) Is "startScreen" going to be where the mapping is? If so, what about ones on a service's success event?
3) Is "directions" always going to be "directions"?

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

How to call mapping with JS

Post by Yurii Orishchuk »

Hi Jack,

1 yes - "homeScreen" should always as "homeScreen"

2 "startScreen" is page where you want to invoke mapping.

3 "directions" should be always "directions"

Regards.

Sami
Posts: 0
Joined: Mon Jun 29, 2015 9:24 pm

How to call mapping with JS

Post by Sami »

Maybe it's not a right way to do this but i can "call" a mapping from JS using an empty generic service and i call the service by the usual call service_name.execute().

After the empty service success (always on succes cause it's empty) i call the mapping in the Apperyio GUI

So i can write all my logic in JS around the service call.

Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

How to call mapping with JS

Post by Jack Bua »

Thanks for this insight Sam. I am new to a lot of this, so why would you want to build your JS around an empty service instead of building a function and calling that instead?

Sami
Posts: 0
Joined: Mon Jun 29, 2015 9:24 pm

How to call mapping with JS

Post by Sami »

With the Appery.io GUI, we can easily create services, services call and mapping function.

We can control a "service call" with Javascript like this : serviceName.execute() but we can't do the same thing with mapping function.

I want to keep the advantage of using the GUI to create my mapping ( cause it's very easy to populate a list with an array in local storage for example ) but i need to put some logic around the execution of this mapping.

In my case, i need to implement this logic :

if (MY test in JS)
= mapping execution on screen 3
if (MY test in JS)
= nothing on screen 3

The easiest way i've find to do this without being forced to code my own mapping in JS is :

if (MY test in JS)
= emptyservice.execute() on screen 3 = on success : Mapping (generated with the GUI)
if (MY test in JS)
= nothing on screen 3

Sorry if i'm not clear I am not comfortable in english..

Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

How to call mapping with JS

Post by Jack Bua »

Ok, Now I see what you are talking about, and I agree. Conditionally mapping is made a lot easier this way. I likely will start doing this. Thanks for the info.

Post Reply