Configure the validation script

  • Release version: Washingtondc
  • Updated February 1, 2024
  • 1 minute to read
  • Use the DataImportValidationConfig script include to configure the validation rules for the staging table.

    Before you begin

    Role required: sn_customerservice.customer_admin

    About this task

    Define the field and record level validation rules for the staging tables. These validation rules are triggered when the agent selects the Validate button after importing data to the staging table. See Import data into the Account Lifecycle Events playbook for details.

    Procedure

    1. Navigate to All > Administration > Script Includes.
    2. Search for the Account Life cycle Events application and select the DataImportValidationConfig script include.
      You can see the validation rules that have been defined for the default tables provided with the base system.
    3. You can define three types of validation rules:
      • Mandatory fields: Specify the mandatory fields that should be present in the staging table.

        For example: In the "sn_acct_lc_account_onb_import_contacts table, you can specify that the following fields are mandatory:

        'u_account', 'u_email', 'u_last_name'

      • Reference fields: Specify the reference fields in the staging table. A reference field stores a reference to a field on another table. When you define a reference field, a relationship is created between the two tables.
        For example: For the sn_acct_lc_account_onb_import_contacts table, you can define the reference field validation as follows:
        "sn_acct_lc_account_onb_import_contacts": {
        		'u_account': {
        			'table_name': 'customer_account',
        			'reference_field': 'name'
        		}
        Where u_account is the name of the field on the staging table, and customer_account is the table and name is the reference field with which it’s associated.
      • Custom validations: Define custom scripts to validate the staging table records. The following is an example of a custom validation script:
        dataImportCustomValidationForCustomerContacts: function(stagingTableGr){
        		try{
                    if(this.debuggingEnabled)
                        this.logs.push('Inside dataImportCustomValidationForCustomerContacts');
        			//Check the Account field's value coming from Excel is matching the corresponding Task or not.
        			while(stagingTableGr.next()){
        				if (global.JSUtil.notNil(stagingTableGr.task) && global.JSUtil.notNil(stagingTableGr.u_account)){
        					if (stagingTableGr.task.company.name != stagingTableGr.u_account){
        						sn_acct_lc.DataImportValidationFunctions.updateStagingTableRecordValidationComments(stagingTableGr, false, 'The Account is not matching with the Case Account.');
        					}
        				}
        			}
        		}
        		catch (err){
        			gs.error('Error while executing - dataImportCustomValidationForCustomerContacts - '+err);
        			if(this.debuggingEnabled)
        				this.logs.push('Error while executing - dataImportCustomValidationForCustomerContacts - '+err);
        			//Update the Validation Comments with the Error
        			sn_acct_lc.DataImportValidationFunctions.updateStagingTableRecordValidationComments(stagingTableGr, false, gs.getMessage('sn_acct_lc.DataImportValidationUtil.ValidationFailed', 'Custom'));
        		}
        	},

        In the preceding example, dataImportCustomValidationForCustomerContacts is the custom validation script. The function calls the stagingTableGr variable (GlideRecord variable) that contains all the records that have been uploaded to the staging table. The script checks the specified conditions using DataImportValidationFunctions and validates the data.

      You can define one or more scripts for new staging tables in the format shown in the preceding example.

    4. Select Update to save any changes made to the script include.