Collection Classes "Struct"
Views (170)
Struct objects (short for structures) are entities that can hold a number of values
of any X++ type. Structs are used to group information about a specific entity.
For example, there may be a need to store information about a customer's name,
group and address and then treat this compound information as one item.
The following methods are commonly used on struct objects:
• add(str _fieldName, anytype _value) - adds a new field to the
struct and assigns the specified value to it.
• exists(str _fieldName) - determines whether a particular field exists
in a struct.
• fieldName(int _index) - returns the name of the field in the struct at
the position specified.
• fields() - returns the number of fields in the struct.
• index(str _fieldName) - calculates the position of a field in the
struct based on its name.
• remove(str _fieldName) - removes a field from a struct.
• value(str _fieldName, anytype _value) - gets or sets the value for a
specific field.
• valueIndex(int _index, anytype _value) - gets or sets the value of
the field at a specific index position in a struct.
The fields in a struct are specified by a data type and a name. Fields can be
added when the struct is created by using the new() method, or they can be
created after the struct has been created using the add() method. If a field is
added using the add() method, the value is specified for the field at the same
time, and the data type is inferred from this value. If a field is added during the
instantiation of the struct, the value() or the valueIndex() method needs to be
used to assign a value to it.
The fields in a struct are arranged in alphabetical order of the field names.
The following is an example using the Struct object.
The result in the infolog should be:
• String : Group
• String : Name
• Integer : Shoesize
Best Regards,
Hossein Karimi
of any X++ type. Structs are used to group information about a specific entity.
For example, there may be a need to store information about a customer's name,
group and address and then treat this compound information as one item.
The following methods are commonly used on struct objects:
• add(str _fieldName, anytype _value) - adds a new field to the
struct and assigns the specified value to it.
• exists(str _fieldName) - determines whether a particular field exists
in a struct.
• fieldName(int _index) - returns the name of the field in the struct at
the position specified.
• fields() - returns the number of fields in the struct.
• index(str _fieldName) - calculates the position of a field in the
struct based on its name.
• remove(str _fieldName) - removes a field from a struct.
• value(str _fieldName, anytype _value) - gets or sets the value for a
specific field.
• valueIndex(int _index, anytype _value) - gets or sets the value of
the field at a specific index position in a struct.
The fields in a struct are specified by a data type and a name. Fields can be
added when the struct is created by using the new() method, or they can be
created after the struct has been created using the add() method. If a field is
added using the add() method, the value is specified for the field at the same
time, and the data type is inferred from this value. If a field is added during the
instantiation of the struct, the value() or the valueIndex() method needs to be
used to assign a value to it.
The fields in a struct are arranged in alphabetical order of the field names.
The following is an example using the Struct object.
1 | Struct struct = new Struct(); |
The result in the infolog should be:
• String : Group
• String : Name
• Integer : Shoesize
Best Regards,
Hossein Karimi
*This post is locked for comments