Create an instance of a GX model with labels

An instance of a GX model with labels can be created using the create static method.

Use the create static method with the list of relevant label references specified as an argument. The list of label references is specified within curly braces using either the static property method or the String constant method. Multiple label references are separated by commas. If an argument specifying GX model options is included, it is located immediately before the list of labels. The syntax with labels referenced by static property is shown below.

var xmlInst = YOURPACKAGE.MODELNAME.TYPENAME.create(object [, GXOptions] [, { label [, label2] }])

Some examples are shown below.

// Create variables that reference the labels by their static properties
var labelSysA = com.mycompany.addressmodel.Address.Label.SysA
var labelSysB = com.mycompany.addressmodel.Address.Label.SysB
// Create instances of the GX model that include various labels referenced by their static properties
var modelSysA = com.mycompany.addressmodel.Address.create(myAddress, {labelSysA})
var modelSysAB = com.mycompany.addressmodel.Address.create(myAddress, {labelSysA, labelSysB})

If the labels are to be ignored and all of the properties in the model are to be included in the instance, refer to the reserved label default_label in the creation statement by using the static property method. You can also refer to this label implicitly by using the static property method with no arguments.

// Create variable that references the default_label
var defLabel = com.mycompany.addressmodel.Address.Label.default_label
// Include all properties in the model and ignore labels
var modelTotalA = com.mycompany.addressmodel.Address.create(myAddress, {defLabel})

Labels referenced using the String constant method are included in a separate list of labels in the model’s create code statement. The list of String constant label references is located after the list of labels referenced by their static properties. Each list of label references is specified within curly braces with multiple label references separated by commas.

var xmlInst = YOURPACKAGE.MODELNAME.TYPENAME.create(object,
                                                    [, GXOptions]
                                                    [, { staticLabel [, staticLabel2] }]
                                                    [, { strConstantLabel [, strConstantLabel2] }])
Note: String constant label references must match the label name for an existing GX model. Be sure to spell String constant label references properly and in the correct case. You can use a String constant to refer to the reserved label, "default_label", explicitly. You can also use the create static method with no arguments to refer to the same reserved label implicitly.
If the list of String constant label references is specified, then the preceding list of static property label references must also be specified. This requirement applies even if the preceding list is designated as an empty list. Both lists can be populated with items.

Some example code statements are shown below.

var label001 = com.mycompany.addressmodel.Address.create(myAddress, {}, {"myLabel001"})
var label002 = com.mycompany.addressmodel.Address.create(myAddress, {}, {"myLabel001", "myLabel002"})
var label003 = com.mycompany.addressmodel.Address.create(myAddress, {labelSysA}, {"myLabel001"})
var label004 = com.mycompany.addressmodel.Address.create(myAddress, {}, {"default_label"})

Static property label references and String constant label references vary in their dependence on the GX models to which they relate. On the one hand, static property label references are specific to the GX models on which they are defined. This is true even if the labels for the references have the same name. On the other hand, String constant label references apply across GX models or within multi-level GX models.

For example, suppose that a GX model GxModel1 defines a property Property1_1 with label SystemA. Assume also that a GX model GxModel2 defines a property Property2_1 with a label having the same name, SystemA. The respective static property references for the SystemA label—GxModel1.Label.SystemA and GxModel2.Label.SystemA—go in the first labels argument position. Alternatively, the String constant reference, "SystemA", goes in the second labels argument position. The references of the static property variety are separate and specific to their corresponding GX models. By contrast, the reference of the String constant variety is model-independent and applies to both Property1_1 on GxModel1 and Property2_1 on GxModel2.

When any single GX model within a parent and child hierarchy defines labels, the label syntax must be used when creating an instance of the parent. The following situations can exist.

  • Parent model does not have labels, child model has labels – The child model can be located at any level below the parent. The parent model will export all of its properties. The child model will export its properties that are assigned the referenced label.
  • Parent model has labels, child model does not have labels – The parent model will export its properties that are assigned the referenced label. The child model will export all of its properties.
  • Both the parent and child model have labels – Both the parent and child models will export their properties that are assigned the referenced labels. A label can be used in both the parent and child models.
    // AddressModel includes child entities.
    // Various properties in AddressModel and its child entities are assigned myGxLabel.
    // The resulting embeddedModel includes all properties in the parent and children with the label.
    var embeddedModel = com.mycompany.addressmodel.Address.create(myAddress, {}, {"myGxLabel"})