Oracle CRM On Demand Desktop Customization Guide > Adding Custom Fields to Oracle CRM On Demand Desktop >

Adding a Cascading Picklist to Oracle CRM On Demand Desktop


Cascading picklists restrict the values of one picklist, the related picklist, based on the value selected in another picklist, the parent picklist. In this example, a parent picklist for opportunities presents a picklist called Status, and drives the value of a related picklist called ReasonWonLost.

Before You Begin

Ensure you have added both picklists to the od_meta_info.xml, od_basic_mapping.xml, and forms_12.xml metadata files. For more information, see Adding a Picklist Field in Oracle CRM On Demand Desktop. Also ensure that the forms_12.xml metadata file contains the following code:

<cell size="22">
  <combobox id="cbx_Status" tab_order="26
  <items format=":[:(Label):]" value_column="Value" has_null_item="true">
  <source type="auto" name="OpportunityStatusPicklist"/>
    <order_by>
      <order ascend="true">SortOrder</order>
    </order_by>
  </items>
    <field>Status</field>
  </combobox>
</cell>
<cell size="22">
  <combobox id="cbx_ReasonWonLost" tab_order="32">
  <items format=":[:(Label):]" value_column="Value" has_null_item="true">
  <source type="auto" name="OpportunityReasonWonLostPicklist"/>
    <order_by>
      <order ascend="true">SortOrder</order>
    </order_by>
  </items>
    <field>ReasonWonLost</field>
  </combobox>
</cell>

For information on the contents of the form_12.xml metadate file, see About the Metadata Files Updated During Customization.

To add a cascading picklist to Oracle CRM On Demand Desktop

  1. In the forms.js metadata file, locate the Opportunity form handler function:

    function od_opportunity_form(ctx)

  2. Add the following code to the Opportunity form handler:

    function Status_control_changed()
    {
      var status = (form.cbx_Status.value != null) ? form.cbx_Status.value : form.item.Status;
      update_picklistReasonWonLost_control(status);
    }

    The Opportunity form handler calls this function when the value of the parent picklist is changed. This function obtains the new value of the parent picklist and passes this value to the related picklist.

  3. Add the following code to the Opportunity form handler:

    function update_picklistReasonWonLost_control(parent_value)
    {
      if (parent_value == null || parent_valueparent_value = "{C22EE487-1B92-4ba0-BC8D-E1368E110FFE}";// this line is just to make sure that we created unique value for the parent value and filtered current picklist correctly
      {
        parent_value = "{C22EE487-1B92-4ba0-BC8D-E1368E110FFE}";// this line is just to make sure that we created unique value for the parent value and filtered current picklist correctly
        form.cbx_ReasonWonLost.items.filter = session.create_expression("ParentCode", "ne", parent_value);
        return;
      }
    var pl_filter = ctx.session.create_criteria("or");
    pl_filter.add(ctx.session.create_expression("ParentCode", "eq", parent_value));
    pl_filter.add(ctx.session.create_expression("ParentCode", "eq", ""));
    pl_filter.add(od_helpers.create_expression_or_null_value_filter(ctx.session, "ParentCode", "eq", null));
    form.cbx_ReasonWonLost.items.filter = pl_filter;
    }

    This function checks the value of the parent picklist. If the value of the parent picklist is empty, then all values in the related picklist are visible. If the parent picklist is populated, then the values in the related picklist are filtered, depending on the value in the parent picklist.

  4. In the Opportunity form handler function, add the following code to the picklist you want to change:

    ctx.events.connect(form.cbx_Status, "changed", Status_control_changed);

  5. In the Opportunity form handler function, add the following code:

    Status_control_changed();

    This code enables the filtering of the parent picklist.

  6. Save the forms.js metadata 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.