Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .objectui-sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26da1a2a37312669c4ad9cffd3b1fb7714afd74b
ac2de168d48712ce31213a5dae05fb5a29b0c5e2
2 changes: 1 addition & 1 deletion examples/app-crm/src/objects/contact.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Contact = ObjectSchema.create({
}),
full_name: Field.formula({
label: 'Full Name',
expression: cel`(first_name == null ? '' : first_name + ' ') + last_name`,
expression: cel`(record.first_name == null ? '' : record.first_name + ' ') + record.last_name`,
}),
email: Field.email({
label: 'Email',
Expand Down
2 changes: 1 addition & 1 deletion examples/app-crm/src/objects/lead.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const Lead = ObjectSchema.create({
/** CEL formula: is this lead in a terminal converted/disqualified state? */
is_closed: Field.formula({
label: 'Is Closed',
expression: cel`status == "converted" || status == "disqualified"`,
expression: cel`record.status == "converted" || record.status == "disqualified"`,
}),
},

Expand Down
10 changes: 7 additions & 3 deletions examples/app-crm/src/objects/opportunity.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ export const Opportunity = ObjectSchema.create({
}),
expected_revenue: Field.formula({
label: 'Expected Revenue',
expression: cel`(amount == null ? 0 : amount) * (probability == null ? 0 : probability) / 100`,
// NOTE: the divisor is the float literal `100.0`, not `100`. cel-js has no
// `double <op> int` arithmetic overload, so `<currency/number field> / 100`
// faults at runtime and the formula silently evaluates to null. Using a
// float literal keeps both operands `double`. See objectstack-formula skill.
expression: cel`(record.amount == null ? 0.0 : record.amount) * (record.probability == null ? 0.0 : record.probability) / 100.0`,
}),
close_date: Field.date({
label: 'Close Date',
Expand Down Expand Up @@ -88,9 +92,9 @@ export const Opportunity = ObjectSchema.create({
type: 'cross_field' as const,
name: 'opp_close_date_not_past',
label: 'Close Date Must Be Future',
description: 'Prevent setting close_date to a date in the past on new records.',
description: 'Prevent back-dating the close_date of an OPEN opportunity. Closed (won/lost) deals legitimately carry a historical close date, so they are exempt.',
fields: ['close_date'],
condition: P`has(record.close_date) && record.close_date < now()`,
condition: P`has(record.close_date) && record.close_date < now() && record.stage != "closed_won" && record.stage != "closed_lost"`,
message: 'Close Date must be today or a future date.',
events: ['insert'],
},
Expand Down