Oleksandr Demchenko · Nov 18, 2022

Trigger, Insert after

Hi, how do I create a trigger that will only set the value of the "Status" field for new objects, not for all available?

Class CarDealer.Order Extends (%Persistent, %Populate)

 Property Title As %String

 Property Status As %String(VALUELIST = ",InProgress,Done,Canceled");

Trigger setStatus [ Event = INSERT, Foreach = row/object, Time = AFTER ]
 &sql(update CarDealer.Order set Status = 'InProgress')

Product version: IRIS 2022.1
0 326
Discussion (2)1
Log in or sign up to continue

Is that what you want to do, or should you be defining your property as:

Property Status As %String(VALUELIST = ",InProgress,Done,Canceled") [ InitialExpression = "InProgress" ];

This makes InProgress the default status when a new CarDealer.Order is created.

Since Trigger code is called after validation and constraint checking, a trigger should not be used to change column values. David's solution is better.