Customizing Defaulting

Defaulting is a type of form function that automatically enters a value in the field of a form when the user creates a new item. It gets the functions and values for these fields from the business_logic.js file that defines the object, and then uses these functions and values to enter the field values. Defaulting uses the following code:

ctx.form_links_manager.init_new()

This code exists in every form handler. It calls the init_new method that resides in the form_links_manager, which is an object that determines the behavior of a form and specifies the relationship that exists between controls that reside in this form and the fields that these controls reference. The init_new method gets information about an object from the business_logic.js file, including information about how the defaulting options are set for the object. You specify these options in the //Defaulting section of the business_logic.js file. For more information about adding default values, see Adding Default Values to Fields.

To customize defaulting

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

  2. Locate the following section:

    //Defaulting
    
  3. Add the defaulting that your customization requires to the section that you located.

    You use the following format to define defaulting:

    scheme.objects.get_object(object_type).get_field(object_field)["source"] = 
    "string_value";
    

    where:

    • object_type identifies the type of object where Siebel CRM Desktop must enter a default value. For example, to add a default value for an action.

    • object_field identifies the name of a field where Siebel CRM Desktop must enter a default value. This field resides in the object type, such as Status.

    • source identifies how Siebel CRM Desktop gets the default value that it enters.

    • string_value identifies where Siebel CRM Desktop gets the string that it uses for the default value.

The following table describes how you set string_value depending on how you set source.

Source Description

initial_value

Siebel CRM Desktop gets the default value from a string that you define. You use the following format:

scheme.objects.get_object(object_type).get_field(object_field)["source"] = "string";

For example:

scheme.objects.get_object("Contact").get_field("Status")[
"initial_value"] = “Active”??;

initial_value_res

Siebel CRM Desktop gets the default value from a string key that the business_logic.js file or the package_res.xml file contains. You use the following format:

scheme.objects.get_object(object_type).get_field(object_field)["source"] = "string_key";

For example, the following code enters a value in the Status field of an action. It uses the lang_action_initial_status string key from the package_res.xml file to get this value:

scheme.objects.get_object("Action").get_field("Status")["
initial_value_res"] = "lang_action_initial_status";

where:

  • lang_action_initial_status identifies the following tag that resides in the package_res.xml file:

<str key="lang_contact_initial_status">Active</str>

This tag sets the value of the string to Active.

initial_value_fn

Siebel CRM Desktop gets the default value from a function. This function resides in the business_logic.js file. You can use initial_value_fn if you use custom logic to determine the default value. You use the following format:

scheme.objects.get_object(object_type).get_field(object_field)["source"] = function_name;

The following example enters a default value in the Percent Complete field of an action. It calls the percent_f function that resides in the business_logic.js file to get this value. The percent_f function calculates and then returns the default value:

scheme.objects.get_object("Action").get_field("Percent 
Complete")["initial_value_fn"] = percent_f;
function percent_f() { return null; };

initial_links_fn

Siebel CRM Desktop gets the default value from a function. You can use initial_links_fn if the user must create a link between objects. initial_links_fn is similar to initial_value_fn except the function must return an array instead of a string. This array must include one or two objects, depending on the types of links that you require Siebel CRM Desktop to create. The following example adds a new link anytime Siebel CRM Desktop creates a new action:

scheme.objects.get_object("Action")["initial_links_fn"] = 
prefill_owner;
function prefill_owner(ctx)
{
  var current_user_id = 
helpers.get_current_user_id(ctx.session);
  if (current_user_id != null)
  {
    return ([
      { "with_id": current_user_id, "tag": "mvg" },
      { "with_id": current_user_id, "tag": "direct" }
    ]);
  }
  else return [];
}