4D v14.3

OB Copy

Home

 
4D v14.3
OB Copy

OB Copy 


 

OB Copy ( object {; resolvePtrs} ) -> Function result 
Parameter Type   Description
object  Object in Structured object
resolvePtrs  Boolean in True = resolve pointers, False or omitted = do not resolve pointers
Function result  Object in Copy of object

The OB Copy command returns an object containing a complete copy of the properties, sub-objects and values for the object.

object must have been defined using the C_OBJECT command.

If object contains pointer type values, by default the copy also contains the pointers. However, you can resolve pointers when copying by passing True in the resolvePtrs parameter. In this case, each pointer present as a value in object is evaluated when copying and its dereferenced value is used.

You want to duplicate an object containing simple values:

 C_OBJECT($Object)
 C_TEXT($JsonString)
 
 ARRAY OBJECT($arraySel;0)
 ALL RECORDS([Product])
 While(Not(End selection([Product])))
    OB SET($Object;"id";[Product]ID_Product)
    OB SET($Object;"Product Name";[Product]Product_Name)
    OB SET($Object;"Price";[Product]Price)
    OB SET($Object;"Tax rate";[Product]Tax_rate)
    $ref_value:=OB Copy($Object//direct copy
    APPEND TO ARRAY($arraySel;$ref_value)
  //the contents of $ref_value are identical to those of $Object
    NEXT RECORD([Product])
 End while
  //the contents of $ref_value
 $JsonString:=JSON Stringify array($arraySel)

You duplicate an object containing pointers:

 C_OBJECT($ref)
 
 OB SET($ref;"name";->[Company]name) //object with pointers
 OB SET($ref;"country";->[Company]country)
 ARRAY OBJECT($sel;0)
 ARRAY OBJECT($sel2;0)
 
 ALL RECORDS([Company])
 
 While(Not(End selection([Company])))
    $ref_comp:=OB Copy($ref// copy without evaluating pointers
  // $ref_comp={"name":"->[Company]name","country":"->[Company]Country"}
    $ref_comp2:=OB Copy($ref;True//copy with evaluation of pointers
  // $ref_comp={"name":"4D SAS","country":"France"}
    APPEND TO ARRAY($sel;$ref_comp)
    APPEND TO ARRAY($sel2;$ref_comp2)
    NEXT RECORD([Company])
 End while
 
 $Object:=JSON Stringify array($sel)
 $Object2:=JSON Stringify array($sel2)
 
  // $Object = [{"name":"","country":""},{"name":"","country":""},...]
  // $Object2 = [{"name":"4D SAS","country":"France"},{"name":"4D, Inc","country":"USA"},{"name":"Catalan","country":"France"}...]

 
PROPERTIES 

Product: 4D
Theme: Objects (Language)
Number: 1225

 
HISTORY 

New
Created: 4D v14

 
SEE ALSO 

OB Get

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)