Oracle CRM On Demand Desktop Customization Guide > Adding One-to-Many and Many-to-Many Associations Between Different Object Types >

Adding One-to-Many Associations Between Different Object Types


A one-to-many association type describes the association between two different object types when a parent object can have many child objects, but each child object can be linked only to one parent object; that is, the child object can have only one link to the parent object.

Before You Begin

Review the chapter on customization in Oracle CRM On Demand Desktop Administration Guide.

This procedure shows how to implement a link from an Account object to a CustomObject4 object. Use this example as a reference to add links between other parent and child objects, and adjust them for your specific requirements. In this procedure, you update the following metadata files:

  • od_basic_mapping.xml
  • od_meta_info.xml
  • connector_configuration.xml
  • business_logic.js
  • views.xml
  • forms_12.xml

For information on the contents of these files, see About the Metadata Files Updated During Customization.

To add a one-to-many association between different object types

  1. Add a link field on the parent object:
    1. Add new fields to the Account type in the od_basic_mapping.xml file, where:
      • CustomObject4Id is the name of the link field where the id attribute of the child object is stored.
      • CustomObject4Name is the name of the field where the name of child object is stored, as shown in the following XML code:

    <field id="CustomObject4Id">
    <reader>
    <mapi_user>
    <user_field id="od CustomObject4Id" ol_field_type="1"></user_field>
    <convertor>
    <binary_hexstring/>
    </convertor>
    </mapi_user>
    </reader>
    <writer>
    <binhex_link>
    <link_writer>
    <outlook_user>
    <user_field id="od CustomObject4Id" ol_field_type="1"></user_field>
    <convertor>
    <binary_hexstring/>
    </convertor>
    </outlook_user>
    </link_writer>
    <resolved_writer>
    <outlook_user>
    <user_field id="od CustomObject4Name" ol_field_type="1"></user_field>
    <convertor>
    <string/>
    </convertor>
    </outlook_user>
    </resolved_writer>
    </binhex_link>
    </writer>
    </field>
    <field id="CustomObject4Name">
    <reader>
    <mapi_user>
    <user_field id="od CustomObject4Name" ol_field_type="1"></user_field>
    <convertor>
    <string/>
    </convertor>
    </mapi_user>
    </reader>
    <writer>
    <outlook_user>
    <user_field id="od CustomObject4Name" ol_field_type="1"></user_field>
    <convertor>
    <string/>
    </convertor>
    </outlook_user>
    </writer>
    </field>

    You can use the ver attribute on the <type> and <field> elements in the od_basic_mapping.xml file to apply the changes made inside those elements:

    • <type> element. If the ver attribute is used during development on the <type> element, then Oracle CRM On Demand Desktop does not apply any change to the description for the object that the id attribute defines until the value of the ver attribute is increased.
    • <field> element. If the ver attribute is used during development on the field element, then Oracle CRM On Demand Desktop does not apply any change to the field description until the value of the ver attribute is increased.
    1. Add the new fields to Account type in the od_meta_info.xml file:

    <field Name="CustomObject4Id" Label="CustomObject4Id" DataType="DTYPE_ID" IsRefObjId="yes" RefObjTypeId="CustomObject4" IsFilterable='no'/>

    1. Extend the <links> section for Account type in the connector_configuration.xml file with the CustomObject4Id field shown in bold font in the following sample XML code:

    <type id="Account" state_field="ObjectState">
    <view label="#obj_account" label_plural="#obj_account_plural" small_icon="type_image:Account:16" normal_icon="type_image:Account:24" large_icon="type_image:Account:48"></view>
    <synchronizer name_format=":[:(AccountName):]" threshold="3">
    <links>
    <link>PrimaryContactId</link>
    <link>ParentAccountId</link>
    <link>OwnerId</link>
    <link>CustomObject4Id</link>
    </links>
    <natural_keys>
    <natural_key>
    <field>AccountName</field>
    <field>Location</field>
    </natural_key>
    </natural_keys>
    </synchronizer>
    </type>

  2. Define the one-to-many relation in the JavaScript code by extending the create_ondemand_meta_scheme2 function in the business_logic.js file with the following functions: add_direct_link() and add_simple_trigger():
    • add_direct_link("Account", "CustomObject4", "CustomObject4Id", false, null, true, "AccountStatus");

      The add_direct_link function defines the one-to-many relation in the data model and accepts the following parameters, where:

      • from_type is the parent object type, for example, Account.
      • to_type is the child object type, for example, CustomObject4.
      • link_field is the link field name on the parent object, for example, CustomObject4Id.
      • required_link is a Boolean data type.
      • refresh_required is used to refresh other form when link changed, if required.
      • primary_on_parent is a Boolean data type.
      • status is the service string field name of the parent object type.
    • add_simple_trigger(form_helpers.native_show, null, "CustomObject4", null, "show");

      The add_simple_trigger function determines the action that is executed when the child object is opened from the parent form so that the child object's form is opened. The function accepts following parameters, where:

      • handler is the function that is called when the trigger is called. Returns a function type.
      • type is the object type on which the trigger is called. Returns a string type.
      • link_to is the link type on which the trigger is called. Returns a string type.
      • tag is the link tag on which trigger is called. Returns a string type.
      • operation is the operation on which the trigger is called. Returns a string type.

        In this case, the add_simple_trigger() function defines that the show operation on the CustomObject4 object triggers a call to the native_show() function in the form_helpers.js file when a UI form of CustomObject4 is displayed. The call passes null values for the type and tag parameters because they are irrelevant for the show operation.

  3. Add the selectors options that specify the settings for the Salesbook dialog box, which display the CustomObject4 records by locating the //selectors options comment in the business_logic.js file, and add your selector options below the comment. For example:

    scheme.objects.get_object("CustomObject4").selectors_options = {
    "source": {
    "caption": "obj_customobj4_plural",
    "view_id": "custom_objects4:salesbook",
    "search_by": ["Name"],
    "online": {
    "like_template": "*{keyword}*"
    }
    }
    };

    where:

    • custom_objects4:salesbook is the id attribute of the child object's Salesbook view.
    • Name is the field defined for the CustomObject4 object to be used for searching purposes.
  4. Add the view definition for the child object to be displayed on the Salesbook view to the views.xml file by locating the <res_root><data_view> elements in views.xml, and placing the following XML code in the <data_view> element:

    <view id="view_od_custom_objects4">
    <image_list>
    <res_id type="normal">type_image:Generic:16</res_id>
    </image_list>
    <columns>
    <column width="305" sort="asc">
    <heading type="string">head_name</heading>
    <field>Name</field>
    </column>
    </columns>
    </view>

    where:

    • <column> is the column element of the grid.
    • <heading> contains the resource id attribute of the column heading.
    • <field> indicates the object's field name taken from the od_basic_mapping.xml file.
    • sort is the sort parameter, which can be asc (ascending) or desc (descending).
  5. Add controls to the forms in the forms_12.xml file as in the following sample code that extends the Account (parent object) form with labels, lookup control, and buttons:

    <cell size="25">
    <stack layout="horz" spacing="5" padding="2">
    <!-- left side captions -->
    <cell size="112">
    <stack spacing="5" layout="vert" padding="4">
    <cell size="21">
    <static id="lbl_co1_name">
    <text>#lbl_co4</text>
    </static>
    </cell>
    </stack>
    </cell>
    <!-- left side fields -->
    <cell>
    <stack layout="vert" spacing="5">
    <cell size="21">
    <stack layout="horz" spacing="3">
    <cell>
    <autocomplete id="CustomObject4Id">
    <field>CustomObject4Id</field>
    <source type="CustomObject4" format=":[:(Name):]"></source>
    </autocomplete>
    </cell>
    <cell size="22" attraction="far">
    <button id="btn_CustomObject4Id" image="lookup_button">
    <text>...</text>
    </button>
    </cell>
    </stack>
    </cell>
    </stack>
    </cell>
    </stack>
    </cell>

    In the XML code, <autocomplete> is a control that the user can use to choose any object. Oracle CRM On Demand Desktop uses an autocomplete control to establish a relationship between objects, for example, to link an account with a CustomObject4. The autocomplete control XML parameters are as follows:

    • <source>. Indicates the object type of the records that are displayed using this control. This parameter has the following attributes:
      • type. The type of the objects displayed in the control.
      • format. The display format.
    • <field>. The name of the field attached to this control. This parameter can be empty.
  6. To register autocomplete control in the forms.js file, add the following code to the parent Account object's form handler:

    register_autocomplete_control(ctx, "CustomObject4", "CustomObject4Id", "btn_CustomObject4Id");

    The generic syntax of the function is as follows:

    function register_autocomplete_control(ctx, link_to, autocomplete_ctrl, show_salesbook_btn)

    The register_autocomplete_control() function accepts the following parameters, where:

    • ctx is the form context object, which is typically passed to the function without changing it.
    • link_to is the type of the child object.
    • autocomplete_ctrl is the id attribute for the autocomplete control in the forms12.xml file.
    • show_salesbook_btn is the id attribute for the Salesbook button in the forms12.xml file.
Oracle CRM On Demand Desktop Customization Guide, Version 5.2 Revision A Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.