Start a conversation

Required Attribute Validation Fails When Value is Zero Due to Incorrect Attribute Type

Problem

When attempting to save or validate a basket in the Solution Console, the operation fails with a validation error for a required attribute that has been set to zero (0). The error typically appears as:

Contract Term is required

or similar validation messages, even though the attribute has been populated with a value of 0.

This prevents basket save, validation, and order generation operations from completing.

Root Cause

The issue occurs when a required attribute is configured with an incorrect data type (typically "String" instead of "Integer" or "Decimal") in the Attribute Definition.

In JavaScript and Salesforce validation logic, the numerical value 0 is considered a "falsy" value. When an attribute is:
1. Marked as required in the Attribute Definition
2. Configured with data type String
3. Populated with the value 0

The validation logic treats 0 as equivalent to an empty or null value, causing the required field validation to fail.

Resolution Steps

  1. Navigate to Attribute Definition Setup:
  2. Go to Setup > Custom Settings > Attribute Definitions
  3. Search for the affected attribute (e.g., "Contract Term")
  4. Open the Attribute Definition record

  5. Update the Data Type:

  6. Locate the "Type" field on the Attribute Definition
  7. Change the value from "String" to:
    • Integer (if the attribute should only store whole numbers)
    • Decimal (if the attribute may store decimal values)
  8. Save the Attribute Definition

  9. Verify the Change in Solution Console:

  10. Open the affected basket in the Solution Console
  11. Open the browser console and run the following command to verify the attribute type:

javascript await CS.SM.getActiveSolution().then(s => s.schema.configurations["<CONFIGURATION_GUID>"].attributes["<ATTRIBUTE_NAME>"] )

  • Check that the type property now shows "Integer" or "Decimal"

  • Retry Save/Validation:

  • In the Solution Console, click "Save" or "Validate"
  • The operation should now complete successfully without the validation error

Option 2: Remove the Required Flag

If the attribute should allow zero or empty values:

  1. Navigate to Attribute Definition Setup:
  2. Go to Setup > Custom Settings > Attribute Definitions
  3. Open the affected Attribute Definition record

  4. Update the Required Flag:

  5. Uncheck the "Required" checkbox
  6. Save the Attribute Definition

  7. Retry Save/Validation:

  8. The validation error should no longer appear when the value is 0

Verification

To verify the attribute configuration in the Solution Console:

await CS.SM.getActiveSolution().then(s => 
  s.schema.configurations["<CONFIGURATION_GUID>"].attributes["<ATTRIBUTE_NAME>"]
)

Expected output for a correctly configured integer attribute:

{
  "name": "Contract Term",
  "type": "Integer",
  "required": true,
  ...
}

Prevention

To prevent this issue when creating new attributes:

  • Use Integer or Decimal data types for numeric attributes that may have a value of 0
  • Reserve the String data type for text-based attributes only
  • When migrating or cloning Attribute Definitions, verify that numeric attributes are not inadvertently set to String type
  • Test validation with edge cases (0, negative numbers, decimals) before deploying to production

Important Notes

  • This issue can affect any required attribute that uses String type and may have a value of 0
  • Changing the attribute type does not require deploying a new Solution Definition version
  • If the attribute is used in multiple Solution Definitions, verify and update each one
  • Compare the configuration of the problematic attribute with other working numeric attributes in your system to identify discrepancies
Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Priyanka Bhotika

  2. Posted

Comments