Create Relationship and Dynamic Relationship Fields
When you call the createRelationshipField method to create a Relationship or Dynamic Relationship field, you must specify the following required parameters, in addition to the required parameters for the createField method. For more information, see Create Fields.
Required Parameters
Parameter
Description
type
Related relationship type. Currently, referential, master, and hierarchical are supported.
targets
Full identifiers for the collection of target objects for the related relationship.
Optional Parameters
Parameter
Description
name
Related relationship name. If not specified, the source object and field identifiers are combined to set this value.
identifier
Related relationship identifier. If not specified, the source object and field identifiers are combined to set this value.
The following fields are automatically set and cannot be overridden:
io_uuid: Automatically generated.
io_deleted: Automatically set to false.
io_namespace: Automatically set to the namespace to which the field belongs.
io_application: Automatically set to the application to which the field belongs.
io_dynamic: Automatically calculated based on the target objects for the relationship. When empty or set to more than one target, automatically set to true. Otherwise, automatically set to false.
io_global_dynamic_relationship: Automatically calculated based on the target objects for the relationship. When empty, automatically set to true. Otherwise, automatically set to false.
Signature fields: created_on, created_by, and so on.
io_owner: Automatically set to the authenticated user.
All other optional relationship fields are set to default values.
createRelationshipField() Method Definition
You specify relationship data by using the com.servicemax.core.definitions.Relationship object. The method creates a field and its related relationship and returns the field. If invalid parameters are specified, or if the field cannot be created on the platform (for example, because it is not valid), an exception is thrown.
public static IMaxObject createRelationshipField(String relatedObjectFullIdentifier, String name, String identifier, String namespaceIdentifier, String applicationName, Relationship relationship, Map<String,Object> additionalFields = [:])
Example
The following example shows how to create a Relationship field named Test Relationship Field with the test_relationship_field identifier for the Showcase object, in the io namespace and Max application. The related relationship is referential and dynamic, with the User and Account objects specified as the target objects.
import com.servicemax.core.utils.Definitions
import com.servicemax.core.definitions.Relationship

def relationship = Relationship.fromMap([io_type: 'referential', targets: ['io_user', 'io_account']])
Definitions.createRelationshipField('io_showcase', 'Test Relationship Field', 'test_relationship_field', 'io', 'Max', relationship)
For more information:
Was this helpful?