Siebel CRM Desktop for Microsoft Outlook Administration Guide > Customizing Siebel CRM Desktop > Validating the Data That Users Enter >

Creating Custom Validations


You can create a custom validation.

To create custom validations

  1. Make sure the form_validator object is defined.

    For more information, see Preparing to Use Validation.

  2. Add the following code to the forms.js file:

    validator.add_custom("function_name","fields_to_highlight","string_key");

    where:

    • function_name is the name of a function that does the validation. CRM Desktop calls this function before it saves the record. This function gets the ctx object as input and allows it to access data and form items. This function must return one of the following values:
      • true. The validation is successful.
      • false. The validation is not successful.
    • fields_to highlight is an array of control identifiers that CRM Desktop highlights in the client if the validation fails.
    • string_key is the string key in the resource file that contains the text for the message that CRM Desktop displays in the client if the validation fails.
  3. Test your changes and then republish the customization package.

    For more information, see Republishing Customization Packages.

Example of Creating a Custom Validation

If the user enters a new opportunity, then the following code makes sure the close date that the user enters occurs later than the current date:

validator.add_custom(validate_close_date,["close_date"],"msg_opportunity_close_date_validation");

To do the validation, this code calls the following validate_close_date function:

function validate_close_date()
{
  var close_date = new Date(ctx.form.item.snapshot['Primary Revenue Close Date']);
  var original_close_date = new Date(ctx.form.item['Primary Revenue Close Date']);
  var today = new Date();
  var utc_today = new Date(today.getUTCFullYear(),today.getUTCMonth(),today.getUTCDate());
  if (close_date != null)
  {
  return close_date < utc_today ? ((original_close_date + 0) == (close_date + 0) ? true :
false ) : true;
  }
  else true;
}

For more information, see Customizing Form Functions.Table 16 describes the parts of the validate_close_date function.

Table 16. Parts of the Validate Close Date Function
Code
Description

var close_date = new

Date(ctx.form.item.snapshot['Primary Revenue Close Date']);

This code creates the close_date variable and sets the value for this variable to the following value:

new

This code does the following:

  1. References the ctx object.
  2. References the form.
  3. Accesses the item. In this example, this item is the current record.
  4. Examines the current state of the record.
  5. Retrieves the Primary Revenue Close Date field.

var original_close_date = new

Date(ctx.form.item['Primary Revenue Close Date']);

This code defines the original_close_date variable. Siebel CRM Desktop enters into this variable the value that the field contains when the user opens the form. To do this, it references the following items:

  • Ctx object
  • Form
  • Item object

var today = new Date();

var utc_today = new Date(today.getUTCFullYear(),

today.getUTCMonth(), today.getUTCDate());

This code creates the following variable and enters the current date into this variable:

today

To support the UTC (Coordinated Universal Time) format that Siebel CRM uses, this code uses the following variable to create a UTC date:

today

if (close_date != null)
{
  return close_date < utc_today ? (
(original_close_date + 0) == (close_date + 0) ? true :
false ) : true;
}
else true;

This code does the following validation:

  • Determines if the user completed the field in the client. If the user did not complete the field, then this code returns the following value:

    true

  • If the close_date occurs before the current date, then this code determines if the close date in the snapshot is different from the close date that the user set when the user opened the record:
    • If these close dates are different, then this situation indicates that the user updated the close date. In this situation the close date must occur after today and the code returns the following value:

      false

    • If these close dates are not different, then this situation indicates that the user did not change the date and this code returns the following value:

      true

Siebel CRM Desktop for Microsoft Outlook Administration Guide Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.