Make Values of a DCL Field Dependent on the Values of Another Field

You can create a field, such as a dynamic choice list field (DCL), that displays different values depending on the values of a different field. In this example, we'll create a DCL field for the Create Contact page that shows addresses for the account associated with the contact. Salespeople can use the field to select an address for the contact from the available account addresses.

Create the Dynamic Choice List Field

  1. Open Application Composer in a sandbox.
  2. In the left panel, make sure that CRM Cloud is selected in the Application field.
  3. Expand the Contact standard object.
  4. Click Fields.
  5. In the Fields page. click Actions > Create.
  6. Select the Choice List (Dynamic) option.
  7. In the Create Dynamic Choice List : Basic Information page, enter the following
  8. Field Sample Entry Explanation
    Display Label Bill-To Address The label users see in the UI.
    Display Width 40 Width of the box displaying the address elements.
    Name BillToAddress Unique internal name.
  9. Leave the Constraints with the default selected values.
  10. Click Next.
  11. On the List of Values page, make these entries:
    Field Sample Entry Explanation
    Related Object Address The source of the values.
    List Selection Display Value Country You can select any of the values as these aren't used for this use case.
  12. You can leave the other sections blank.
  13. Click Submit.

Specify the DCL Field Behavior and Add It to the Layout

  1. Open Visual Builder Studio.
  2. Click the Layouts tab.
  3. On the Layouts tab, click CX Sales > Contacts.

    Screeshot highligting the Layouts tab and Contacts.
  4. Click Rule Sets > Create Layout (CX Sales).

    Rule Sets tab highlighting Create Layout dynamic form
  5. Duplicate the default rule with the Also create a copy of the layout option selected.
  6. Add a rule condition to the new rule.
  7. Click Open on the new layout rule to open the layout copy.

    Rule with location of Open action button highlighted.
  8. Find the PersonDEO_Bill_To_Address_id_c (Bill-to Address) field and add it to the layout (highlighted by callout 1 in the following screenshot)
  9. Create a variable for the field template:

    1. Still in the Contact layout tab, click Variables

    2. Click Create Variables (callout 1 in the following screenshot).
    3. Enter a variable ID, such as billToAddresses.
    4. For Type, select Any.
  10. Create a field template that you'll need for the layout:

    1. Click the Rule Sets tab.
    2. Click Create for the Template field (callout 2) in the Field (right-hand) pane.

      Screenshot showing key navigation to create a template for a field
    3. In the Create Template window, enter a name with no spaces, such as billToAddressTemplate and leave the Enable Extension option selected.
    4. Click Create.
    5. Click the Code option
    6. Here's sample code to enter:

      <template id="billToAddress">
        <oj-select-single label-hint="billToAddressID" data="[[$variables.billToAddresses]]" value="{{$value}}"></oj-select-single>
      </template>
      
  11. Create an action chain that does the following:
    • Check if the updated field in the record is the account Party ID.
    • If the account Party ID is updated, then store that Party ID in the constant accountPartyNumber
    • Create a REST call that returns all of the addresses for that Party ID
    • Store the returned addresses (FormattedAddresses) in an array.
    • Assign the values in the array to the variable billToAddresses which will be part of the Create Contact UI.
    1. On the Contacts tab, click Action Chains.

      Action Chains tab selected with the Create Action Chain window open
    2. Click Create Action Chain (+Action Chain).
    3. In the Create Action Chain window, leave the Java Script option selected and enter any name as an ID, in this example: GetAddresses.
    4. Click Create.
    5. Switch to the Code view and enter the code:
    6. Here's a sample:

      define([
        'vb/action/actionChain',
        'vb/action/actions',
        'vb/action/actionUtils',
        'ojs/ojarraydataprovider',
        ], (
        ActionChain,
        Actions,
        ActionUtils,
        ArrayDataProvider
      ) => {
        'use strict';
        class test extends ActionChain {
          /**
           * @param {Object} context
           * @param {Object} params
           * @param {{row:object,related:object[],fieldsToShow:string[]}} params.previous
           * @param {{row:object,previousRow:object,modifiedField:string,pickedRowsData:object,parentRow:object,mode:string}} params.event
           * @return {{row:object,related:object[],fieldsToShow:string[]}}
           */
          async run(context, { previous, event }) {
            const { $layout, $extension, $responsive, $user } = context;
            if (event.modifiedField === 'AccountPartyId') {
              const accountPartyNumber = event.pickedRowsData ['accounts.AccountPartyId'];
              const addressesResponse = await Actions.callRest(context, {
              endpoint: 'oracle_cx_salesUI:cx/getall_accounts-Address',
              uriParams:{
                 'accounts_Id': accountPartyNumber.PartyNumber,
              },
              });
             if (addressesResponse.ok){
             const billToAddresses = addressesResponse.body.items.map((address)=> {return {label:address.FormattedAddress,value:address.FormattedAddress}});
                   $layout.variables.billToAddresses = new ArrayDataProvider(billToAddresses,{keyattributes:"value"});
             }
            }
            if (event.modifiedField === 'PersonDEO_BillToAddress_Id_c'){
             debugger;
            }
          return previous;
          }
        }
        return test;
      });
  12. Create an event listener for the field template:

    1. Click the Event Listeners tab.
    2. Click the Create Listener button (+Event Listener).
    3. In the Create Event Listener page, select ContactsOnFieldValueChangeEvent.
    4. Click Next
    5. Select the action chain you just created. In this example, GetAddresses.
    6. Click Finish.
  13. Test your field:

    1. Click the Preview button to test your newly-created field.

      This is a screenshot of the Preview button in Visual Builder Studio.
    2. On the Contacts list page, enter Create Contact in the Action Bar.
    3. Select an account that includes a number of addresses.
    4. Click in the Bill-To-Address field to select an address.