Contents - Index


CustomPut (function)

CustomPut(sField,sValue,[sCode]) : string  
 
Direct Sql updates are allowed on the custom table, but that can be somewhat counter intuitive to use.

Use this function for an easy way to update custom data. This function is the is the complement to the CustomGet() function.

sField - The name of the field to update
sValue - The value to place in this field
sCode - Optional. If omitted then the code for the current cache in the grid will be used. Otherwise enter the code of the cache to be updated.

The return string is empty if the function was successful, otherwise it will contain the error message describing the problem. 

If there is an error (for example a field name which is not defined in the custom table), the return string will begin with "*Error*" (without the quotes). Macro authors should really check the return value to make sure the function completed normally.

If this function is used multiple times in a macro then you should wrap the use inside a transaction, otherwise the macro will run very slowly (each use will force a discreet disk write to the database).

Although this could be done using direct update, here is the sample code to update all records in your current filter such that the contents of the custom field "MyData" is updated with the contents of "UserData2":
 

$recno = 0
Transaction Action=Begin
While not($_Eol)
  $recno = $recno + 1
  IF frac($Recno/10) = 0
    ShowStatus msg="Processing record $recno of $_count"
  endIf 
  $result = CustomPut("MyData",$d_UserData2)
  if left($result,7) = "*Error*"
    Transaction Action=End # commit changes made thus far
    Cancel msg=$result # abort macro if we get an error
  Endif
  GoTo Position=Next
EndWhile
Transaction Action=End
Goto Position=Top


Alpha List         Category List