Skip to content
Groovy 31 – Create a 1:M relationship via Groovy script

Object Relationship Creation

Object A is related in a 1:M relationship with Object B. To create one or more Object B under Object A, you need to populate the relationship Id with the Id of Object A.

When you create a relationship between two custom objects, the relationship attribute to populate is in the format: [ObjectName]_Id_[RelationshipName].

Groovy Code

        // Groovy Code Snippet
        def objectAId = 'VALUE_OF_OBJECT_A_ID'  // Replace with actual Object A Id
        def objectB = [ // Example of Object B creation
            Attribute1: 'Value1',
            Attribute2: 'Value2',
            // Add more attributes as needed
            ObjectA_Id_RelationshipName: objectAId  // Set the relationship Id
        ]
        
        // Assuming 'createObjectB' is a method to create Object B
        def createdObjectB = createObjectB(objectB)
        

This Groovy code snippet demonstrates how to set the relationship Id between Object A and Object B. Replace VALUE_OF_OBJECT_A_ID with the actual Id of Object A and ensure the attributes match your specific use case.