4D v16.3

OB SET

Home

 
4D v16.3
OB SET

OB SET 


 

OB SET ( object ; property ; value {; property2 ; value2 ; ... ; propertyN ; valueN} ) 
Parameter Type   Description
object  Object, Object Field in Structured object
property  Text in Name of property to set
value  Text, Date, Boolean, Pointer, Number, Object in New value of property

The OB SET command creates or modifies one or more property/value pairs in the language object designated by the object parameter.

object must have been defined using the C_OBJECT command or designate a 4D object field.

Note: This command supports attribute definitions in 4D Write Pro objects, like the WP SET ATTRIBUTES command (see example 10). However, unlike WP SET ATTRIBUTES, OB SET does not allow you to handle a picture variable or field directly as an attribute value.

In the property parameter, pass the label of the property to be created or modified. If the property already exists in object, its value is updated. If it does not exist, it is created.
Note that the property parameter is case sensitive. 

In the value parameter, pass the value you want to set for the property. Several data types are supported. Note that:

  • if you pass a pointer, it is kept as is; it is evaluated using the JSON Stringify command,
  • dates are stored in the format "YYYY-MM-DDTHH:mm:ss.SSSZ". When converting 4D dates into text prior to storing them in the object, by default the program takes the local time zone into account. You can modify this behavior using the JSON use local time selector of the SET DATABASE PARAMETER command.
  • if you pass a time, it is stored as a number of milliseconds (Real) in object.
  • if you pass a language object, the command uses the object reference and not a copy.

Creating an object and adding a text type property:

 C_OBJECT($Object)
 OB SET($Object ;"FirstName";"John";"LastName";"Smith")
  // $Object = {"FirstName":"John","LastName":"Smith"}

Creating an object and adding a Boolean type property:

 C_OBJECT($Object)
 OB SET($Object ;"LastName";"smith";"age";42;"client";True)
  // $Object = {"LastName":"smith","age":42,"client":true}

Modifying a property:

  // $Object = {"FirstName":"John","LastName":"Smith"}
 OB SET($Object ;"FirstName";"Paul")
  // $Object = {"FirstName":"Paul","LastName":"Smith"}

Adding a property:

  // $Object = {"FirstName":"John","LastName":"Smith"}
 OB SET($Object ;"department";"Accounting")
  // $Object = {"FirstName":"Paul","LastName":"Smith","department":"Accounting"}

Renaming a property:

 C_OBJECT($Object)
 OB SET($Object ;"LastName";"James";"age";35)
  // $Object = {"LastName":"James","age":35}
 OB SET($Object ;"FirstName";OB Get($Object ;"LastName"))
  // $Object = {"FirstName":""James","nom":"James","age":35}
 OB REMOVE($Object ;"LastName")
  // $Object = {"FirstName":""James","age":35}

Using a pointer:

  // $Object = {"FirstName":"Paul","LastName":"Smith"}
 C_TEXT($LastName)
 OB SET($Object ;"LastName";->$LastName)
  // $Object = {"FirstName":"Paul","LastName":"->$LastName"}
 $JsonString:=JSON Stringify($Object)
  // $JsonString="{"FirstName":"Paul","LastName":""}
 $LastName:="Wesson"
 $JsonString:=JSON Stringify($Object)
  // $JsonString="{"FirstName":"Paul","LastName":"Wesson"}

Using an object:

 C_OBJECT($ref_smith)
 OB SET($ref_smith ;"name";"Smith")
 C_OBJECT($ref_emp)
 OB SET($ref_emp ;"employee";$ref_smith)
 $Json_string :=JSON Stringify($ref_emp)
  // $ref_emp = {"employee":{"name":"Smith"}} (object)
  // $Json_string = "{"employee":{"name":"Smith"}}" (string)

You can also change a value on the fly:

 OB SET($ref_smith ;"name";"Smyth")
  // $ref_smith = {"employee":{"name":"Smyth"}}
 $string:=JSON Stringify($ref_emp)
  // $string = "{"employee":{"name":"Smyth"}}"

If you have defined the [Rect]Desc field as an object field, you can write:

 CREATE RECORD([Rect])
 [Rect]Name:="Blue square"
 OB SET([Rect]Desc;"x";"50";"y";"50";"color";"blue")
 SAVE RECORD([Rect])

You want to export data in JSON that contains a converted 4D date. Note that conversion occurs when the date is saved in the object, so you must call the SET DATABASE PARAMETER command before calling OB SET:

 C_OBJECT($o)
 SET DATABASE PARAMETER(JSON use local time;0)
 OB SET($o ;"myDate";Current date// JSON conversion
 $json:=JSON Stringify($o)
 SET DATABASE PARAMETER(JSON use local time;1)

In the method of a form containing a 4D Write Pro area, you can write:

 If(Form event=On Validate)
    OB SET([MyDocuments]My4DWP;"myatt_Last edition by";Current user)
    OB SET([MyDocuments]My4DWP;"myatt_Category";"Memo")
 End if

You can also read custom attributes of the documents:

 vAttrib:=OB Get([MyDocuments]My4DWP;"myatt_Last edition by")



See also 

OB REMOVE
OB SET ARRAY
OB SET NULL

 
PROPERTIES 

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

This command can be run in preemptive processes

 
HISTORY 

Created: 4D v14
Modified: 4D v15
Modified: 4D v15 R4

 
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)