4D v16.3

MOBILE Return selection

Home

 
4D v16.3
MOBILE Return selection

MOBILE Return selection 


 

MOBILE Return selection ( aTable ) -> Function result 
Parameter Type   Description
aTable  Table in Table whose current selection you want to return
Function result  Object in Wakanda-compliant selection

The MOBILE Return selection command returns a JSON object that contains the current selection of aTable transformed into a Wakanda-compliant entity collection. 

This command is intended to be called in the context of a 4D Mobile connection, usually between your 4D application and a Wakanda application (via REST). When a 4D Mobile connection is established and appropriate access rights have been configured, a Wakanda application can execute a 4D project method that returns a value in the $0 parameter.

The MOBILE Return selection command allows you to return, in $0, the current selection of records of the aTable table, in the form of an entity collection object in JSON format. This object is compliant with Wakanda entity collections that contain a selection of records (i.e. of entities).

Keep in mind that 4D Mobile accesses require specific configurations in your 4D database:

  • The Web server must be launched,
  • The "Activate 4D Mobile Service" option must be checked in your Database settings,
  • You must have a valid license,
  • Tables and fields used must have the "Expose for 4D Mobile" option checked (set by default). 
  • Called methods must have the "Available through 4D Mobile call" option checked (not set by default). 

Note that you can pass any valid table of the database in aTable, and not necessarily the table with which the project method has been associated in its properties. This parameter is only used on the Wakanda side to define the objects for which the method can be called. 

For more information on 4D Mobile configuration, please refer to the 4D Mobile documentation. 

Example  

You want to display the current selection of the [Countries] table in a Wakanda grid, based on a query.

You write the following 4D method:

  //FindCountries project method
  //FindCountries( string ) -> object
 
 C_TEXT($1)
 C_OBJECT($0)
 QUERY([Countries];[Countries]ShortName=$1+"@")
 $0:=MOBILE Return selection([Countries])

The returned selection can be used directly in Wakanda as a valid collection.

In the Wakanda server model connected to 4D via 4D Mobile, you have created a page with a grid bound to the 4D Countries table. By default, at runtime, all entities from the 4D table are displayed:

The code of the button is:

button1.click = function button1_click (event)
    {
        sources.countries.FindCountries("i", {  //we call the 4D method, "i" is passed as $1
                onSuccess:function(coll){  //callback function (asynchronous), receives $0 as parameter
                    sources.countries.setEntityCollection(coll.result); //replace the current entity collection
                                // with the one in the coll.result object
                }
            });        
    };

As a result, the grid is updated:

 
PROPERTIES 

Product: 4D
Theme: Selection
Number: 1315

This command can be run in preemptive processes

 
HISTORY 

Created: 4D v14 R3

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)