KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method to set 4D Mobile attribute on a method
PRODUCT: 4D | VERSION: 15 | PLATFORM: Mac & Win
Published On: June 11, 2015

In v15, attributes for 4D mobile are now disclosed in the method when using the METHOD GET ATTRIBUTES command. Here is a utility method UTIL_SET_4D_MOBILE_METHOD_ATTR to set the 4D mobile attributes during run time:

// ----------------------------------------------------------------------
// Name: UTIL_SET_4D_MOBILE_METHOD_ATTR
// Description: Method will set the 4D Mobile attribute of a method.
//
// Parameters:
// $1 (TEXT) - Method Name
// $2 (LONG INT) - Scope:
// 0 - Disable Attribute
// 1 - Table
// 2 - Current Record
// 3 - Current Selection
// $3 (TEXT) - Table Name
// Output:
// $0 (LONG INT) - Status of setting attribute
// 0 - Success
// 1 - Error: Method Name not found
// 2 - Error: Table Name not found
// 3 - Error: Scope incorrect choice
// 4 - Error: Insufficient parameters
// ----------------------------------------------------------------------
ARRAY TEXT(arrPaths;0) // text arrays
ARRAY TEXT(arrCodes;0)
C_TEXT($1;$method_name)
C_TEXT($3;$table_name)
C_LONGINT($2;$scope_choice)
C_LONGINT($loc_method;$i)
C_LONGINT($0)
C_BOOLEAN($found_table_name)
C_OBJECT($attributes)
C_OBJECT($4D_Mobile_Att)

if (Count parameters=3)

   $method_name:=$1
   $scope_choice:=$2
   $table_name:=$3

   METHOD GET PATHS(Path project method;arrPaths) // Get paths for Project methods
   $loc_method:=Find in array(arrPaths;$method_name;1)

   if ($loc_method>0)

       // Finding the table
      $found_table_name:=False
      For ($i;1;Get last table number)
         If ($table_name=Table name($i))
            $found_table_name:=True
         End if
      End for

      If (($found_table_name=True) | ($scope_choice=0))

         METHOD GET ATTRIBUTES(arrPaths{$loc_method};$attributes) // Method Attributes

         Case of
         : ($scope_choice=0)
         OB SET($4D_Mobile_Att;"scope";"none")

         : ($scope_choice=1)
         OB SET($4D_Mobile_Att;"scope";"table")

         : ($scope_choice=2)
         OB SET($4D_Mobile_Att;"scope";"currentRecord")

         : ($scope_choice=3)
         OB SET($4D_Mobile_Att;"scope";"currentSelection")

         Else
            $0:=3 // Scope incorrect choice
         End case

         If (($scope_choice>=0)&($scope_choice<=3))
          OB SET($4D_Mobile_Att;"table";$table_name)
          OB SET($attributes;"published4DMobile";$4D_Mobile_Att)
          METHOD SET ATTRIBUTES(arrPaths{$loc_method};$attributes)
          $0:=0 // Success
         End if

      Else
          $0:=2 // Table Name not found
      End if
    Else
       $0:=1 // Method Name not found
    End if

Else
   $0:=4 // Insufficient parameters
End if



Example #1 Disable 4D Mobile Attribute:

C_LONGINT($status)

$status:=UTIL_SET_4D_MOBILE_METHOD_ATTR ("Method1";0;"") // Also can be entered ("Method1";"";"")





Example #2 Changing the Scope to "Current Record":

C_LONGINT($status)

$status:=UTIL_SET_4D_MOBILE_METHOD_ATTR ("Method1";2;"Table_1")





Example #3 Changing the Table to "Table_2":

C_LONGINT($status)

$status:=UTIL_SET_4D_MOBILE_METHOD_ATTR ("Method1";2;"Table_2")





Example #4 Changing the Scope and Table:

C_LONGINT($status)

$status:=UTIL_SET_4D_MOBILE_METHOD_ATTR ("Method1";3;"Table_1")





See Also: