Skip to content

Commit ec694f0

Browse files
committed
fix(spec): rewrite the two cross_field Salesforce-example conditions in evaluable CEL
Example 1 (close date in the current or a future month) is rewritten to a condition that is TRUE on the violation - a close date before the first day of the current month - using the stdlib date(), today() and addDays() plus CEL's getDate() accessor. Example 3 (products required for Closed Won) keeps its direction and drops the lone `=` and the `AND` keyword. The Salesforce-formula side of each example is unchanged. TSDoc text only. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QcAS3qiYYZNezaxZxaUdMV
1 parent a9fb83e commit ec694f0

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@objectstack/spec": patch
3+
---
4+
5+
The two `cross_field` "Salesforce Examples" in the `CrossFieldValidationSchema` TSDoc (`packages/spec/src/data/validation.zod.ts`) now show a `condition` the evaluator accepts, so an author or agent who copies the documented "ObjectStack Equivalent" gets a rule that evaluates, and Example 1's rule fires on the records it names as invalid (#20252).
6+
7+
Clause-②: no
8+
9+
- Example 1, "Close Date Must Be In Current or Future Month": `MONTH(close_date) >= MONTH(TODAY()) AND YEAR(close_date) >= YEAR(TODAY())` becomes `date(record.close_date) < addDays(today(), 1 - today().getDate())`. The old string did not parse (`AND` is not CEL, and `close_date` had no `record.` root). It was also inverted: a `cross_field` condition that evaluates TRUE is the violation, and the old condition was TRUE on the records the rule should accept. The new condition is TRUE when the close date falls before the first day of the current month. It uses only the formula stdlib's `date()`, `today()` and `addDays()` plus CEL's built-in `getDate()` timestamp accessor.
10+
- Example 3, "Opportunity Must Have Products": `products = null AND stage = "closed_won"` becomes `isBlank(record.products) && record.stage == "closed_won"`. A lone `=` is a CEL parse error and `AND` is not CEL. The direction is unchanged.
11+
12+
The Salesforce-formula side of each example is unchanged. This is TSDoc text only, with no schema, behaviour or export change.

‎packages/spec/src/data/validation.zod.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export const FormatValidationSchema = lazySchema(() => strictObject({
237237
* {
238238
* type: 'cross_field',
239239
* name: 'close_date_future',
240-
* condition: 'MONTH(close_date) >= MONTH(TODAY()) AND YEAR(close_date) >= YEAR(TODAY())',
240+
* condition: 'date(record.close_date) < addDays(today(), 1 - today().getDate())',
241241
* fields: ['close_date'],
242242
* message: 'Close Date must be in the current or a future month'
243243
* }
@@ -271,7 +271,7 @@ export const FormatValidationSchema = lazySchema(() => strictObject({
271271
* {
272272
* type: 'cross_field',
273273
* name: 'products_required_for_won',
274-
* condition: 'products = null AND stage = "closed_won"',
274+
* condition: 'isBlank(record.products) && record.stage == "closed_won"',
275275
* fields: ['products', 'stage'],
276276
* message: 'Opportunity must have products to be marked as Closed Won'
277277
* }

0 commit comments

Comments
 (0)