Page 1 of 1

How to call mapping with JS

Posted: Sat Jul 18, 2015 6:34 am
by Sami

Hello,

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

Image


How to call mapping with JS

Posted: Mon Jul 20, 2015 5:51 am
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


How to call mapping with JS

Posted: Fri Jul 24, 2015 5:38 pm
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"?


How to call mapping with JS

Posted: Mon Jul 27, 2015 3:22 am
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.


How to call mapping with JS

Posted: Mon Jul 27, 2015 7:38 pm
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.


How to call mapping with JS

Posted: Mon Jul 27, 2015 8:27 pm
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?


How to call mapping with JS

Posted: Tue Jul 28, 2015 12:32 am
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..


How to call mapping with JS

Posted: Tue Jul 28, 2015 1:14 am
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.