%Template

This special method populates the non-object elements of an internal object — fields and array items — from a dynamic array.

All special method names and keywords are case-insensitive.

Syntax

object->{element->}%Template(FromMV, dyn-array}

Syntax elements

objectAn expression that evaluates to an internal object.

elementAn element within object.

dyn-arrayAn expression that evaluates to a dynamic array.

Applicability

Internal objects only.

Examples

Uses the Dylan dynamic array to populate the Singer object (a copy of the Artist object as defined by a JSON document). Note the use of the @AM predefined symbol in the dynamic array.

Artist = %New(JSON, '{ "firstName": "", "lastName": "", "dateOfBirth": null }')
Dylan  = "Bob":@AM:"Dylan":@AM:"1941"

Singer = %New(Object, Artist)
Singer->%Template(FromMV, Dylan)

PRINT Singer->%ToJSON(1)

This also produces

{ "firstName" : "Bob", "lastName" : "Dylan", "dateOfBirth" : 1941 }

See also

%New, %ToJSON