Configuring an Unbounded Picklist That Adds New Values to Fields and to the Picklist

This topic describes how to configure an unbounded picklist so that the user can enter a new value in the field associated with this picklist. It also describe how to add the value that the user enters to the values that this picklist displays. The example in this topic modifies the picklist that the user uses to set the status of an opportunity.

Configuring an unbounded picklist that adds new values to fields and to the picklist

  1. Replace the combobox control:

    1. Use an XML editor to open the form_xx.xml file.

    2. Locate the following code:

      <combobox id="status" tab_order="14">
        <items format=":[:(Label):]" value_column="Value" has_null_item="true">
          <source type="auto" name="OpportunityStatusPicklist"></source>
          <order_by>
            <order ascend="true">SortOrder</order>
          </order_by>
        </items>
        <field>Status</field>
      </combobox>
      

      This code specifies the combobox control that the user uses to set the opportunity status. For more information, see Combobox Control of the Forms File.

    3. Replace the code you located in step b with the following code:

      <cell>
        <edit id="status" tab_order="14">
          <field value="string">Status</field>
        </edit>
      </cell>
        <cell size="21">
        <button id="btn_opportunity_status" tab_order="141">
          <text>...</text>
        </button>
      </cell>
      

      This step replaces the combobox control code with an edit control that the user can use to enter characters, and a button that the user can click to display the SalesBook control that contains an autocomplete list.

    4. Save your modifications.
  2. Specify options for the SalesBook control in the business_logic.js file:

    1. Use a JavaScript editor to open the business_logic.js file.

    2. Add the following code:

      scheme.objects.get_object("OpportunityStatusPicklist").selectors_options = {
      "source": {
      "caption": "obj_opportunity_status_plural",
      "view_id": "opportunity_status:salesbook",
      "search_by": ["Label"],
      "online": {
      "like_template": "*{keyword}*"
      }
      }
      };
      

      This code specifies options for the SalesBook control, such as the caption and view name that Siebel CRM Desktop displays with the SalesBook control.

    3. Save, and then close the business_logic.js file.
  3. Specify options for the SalesBook control in the views.xml file:

    1. Use an XML editor to open the views.xml file.

    2. Add the following code:

      <view id ="opportunity_status:salesbook">
        <image_list>
          <res_id type="normal">type_image:Generic:16</res_id>
        </image_list>
        <columns>
          <column width="100">
            <heading type="string">head_name</heading>
            <field>Label</field>
          </column>
        </columns>
      </view>
      

      where:

      • opportunity_status is the view you specified in step b.

      • head_name is a string key that specifies the heading that Siebel CRM Desktop displays in the SalesBook control. You must make sure that the package_res.xml file specifies this head_name.

    3. Save, and then close the views.xml file.

    4. Use an XML editor to open the package_res.xml file.

    5. Make sure the following code exists:

      <str key="head_name">
      ...
      </str>
      

      If this code does not exist, then add it now. If necessary, you can modify the head_name string key.

  4. Add a controller and a link:

    1. Use a JavaScript editor to open the forms.js file.

    2. Locate the form handler you must modify.

      You can add a controller and a link to the handler of any object. In this example you modify the following handler for the Opportunity object:

      function opportunity_form(ctx)
      {
      ...
      }
      
    3. Locate the opportunity_form function that resides in the form handler that you located in step b.

    4. Add the following code to the opportunity_form function:

      function my_link()
        {
        this.type = ctx.item_ex.get_type();
        this.link_to = "OpportunityStatusPicklist";
        this.tag = "local_opportunity_status_link";
        this.create = function(ctx, spec_ctx)
        {
          var opportunity_status = ctx.session.open_item(spec_ctx.with_id);
          ctx.form.item["Status"] = opportunity_status.Value;
          ctx.form.status.value = opportunity_status.Value;
          return ({});
        }
        }
      

      This code adds the controller that Siebel CRM Desktop uses to control the button that you add in step c. Siebel CRM Desktop uses this controller to call the SalesBook dialog box.

    5. Add the following code immediately after the code you added in step d:

      
      ctx.links.add_link(new my_link());
      var opportunity_status_options =
      {
        "tag": "local_opportunity_status_link",
        "link_to": "OpportunityStatusPicklist",
        "sb_custom_view": true,
        "btn_show": ctx.form.btn_opportunity_status
      }
      ctx.form_links_manager.add_controller(new mvg_dialogs.custom_sales_book(), 
      opportunity_status_options);
      

      This code specifies the link that Siebel CRM Desktop uses to add a value to the field.

    6. Save, and then close the forms.js file.

  5. Add a new dialog box that allows the user to enter values:

    1. Use an XML editor to open the dialogs.xml file.

    2. Add the following code between any <dialog></dialog> tags:

      <dialog id="Opportunity Status Dlg">
        <script><![CDATA[
        ]]></script>
        <layout sizable="true" id="General" min_height="120" min_width="400" 
        caption="Opportunity Status"
        small_icon="type_image:Generic:16">
        <appearance height="120" width="400" position="parent_center"/>
        <cell>
          <stack layout="horz" padding="5">
        <cell>
          <stack layout="vert" padding="10" spacing="10">
        <cell>
          <stack layout="horz" spacing="3" padding="5">
          <!-- left side captions -->
            <cell size="128">
            <stack spacing="5" layout="vert" padding="4">
            <cell size="21">
            <static id="lbl_label" tab_order="1">
              <text>Label</text>
            </static>
           </cell>
            <cell size="21">
              <static id="lbl_value" tab_order="2">
                <text>Value</text>
              </static>
            </cell>
          </stack>
        </cell>
          <!-- left side fields -->
          <cell>
            <stack layout="vert" spacing="5">
          <cell>
            <edit id="label" tab_order="3">
              <field value="string">Label</field>
            </edit>
          </cell>
        <cell>
        <edit id="value" tab_order="4">
          <field value="string">Value</field>
        </edit>
        </cell>
          </stack>
            </cell>
              </stack>
                </cell>
                  <cell size="2">
                    <edge id="close_border"/>
                  </cell>
                    <cell size="24">
                  <stack layout="horz" spacing="5" padding="5">
                    <cell size="80">
                    <button id="btn_ok" tab_order="5" image="button_image:Ok:16" 
      align="left">
                    <text>#btn_ok</text>
                    </button>
                  </cell>
                    <cell size="80">
                      <button id="btn_cancel" tab_order="6" 
      image="button_image:Cancel:16"
                        align="left">
                        <text>#btn_cancel</text>
                    </button>
                   </cell>
                </stack>
              </cell>
            </stack>
          </cell>
          </stack>
          </cell>
        </layout>
      </dialog>
      
    3. Save, and then close the dialogs.xml file.

  6. Add the trigger that Siebel CRM Desktop uses to call the dialog box:

    1. Use a JavaScript editor to open the business_logic.js file.

    2. Locate the following code:

      with (scheme.triggers)
      {
      ...
      }
      
    3. Add the following code to the code you located in step b:

      add_simple_trigger(form_helpers.create_dialog_show("Opportunity Status Dlg", 
      { "form_handler": null }), null,
      "OpportunityStatusPicklist", null, "show");
      

      This code specifies to call the dialog box that you added in step 5 if the user clicks New in the SalesBook dialog box.

    4. Save, and then close the business_logic.js file.

  7. Test your work:

    1. Log into the client.

    2. Navigate to the Opportunity form.

    3. Enter a value in the Status field, and then step off the field.

    4. Click the Status field, and then make sure Siebel CRM Desktop displays the value you added in the picklist.