From the Documentation, the .Triggers of the %Dictionary.ClassDefinition is defined as a parent-child relationship.
If you want to remove the trigger from the class, simply change:
if cdef.Triggers.GetAt(i).Name = "TriggerOnInsert"
{
set oid = cdef.Triggers.GetAt(i).%Id()
write oid,!
set status = ##class(%Dictionary.TriggerDefinition).%Delete(oid)
f $SYSTEM.Status.IsError(status) {
Do DecomposeStatus^%apiOBJ(%objlasterror,.Err)
Write !,Err(Err)
}to:
if cdef.Triggers.GetAt(i).Name = "TriggerOnInsert"
{
//Remove at returns the OID, not the ID
set oid = cdef.Triggers.RemoveAt(i)
if (oid="")
{
write oid,!
} else {
write "No trigger removed",!
}
}Doug Pickering wrote:
Thank you Ram�n,
I have had a look at the documentation in that area and am now starting to experiment. It looks like that is a good place to be. I have enclosed a bit of code from what I am now doing. It intends to delete a trigger if it exists, before creating it. If you (or anyone else) knows what the error is trying to say I would be grateful.
Many thanks,
Doug Pickering
ClassMethod MakeTriggers(name as %String) { Set cdef = ##class(%Dictionary.ClassDefinition).%OpenId(name) Write "Adding triggers to " _ cdef.Name ,!
Set count = cdef.Triggers.Count() For i = 1:1:count { if cdef.Triggers.GetAt(i).Name = "TriggerOnInsert" { set oid = cdef.Triggers.GetAt(i).%Id() write oid,! set status = ##class(%Dictionary.TriggerDefinition).%Delete(oid) If $SYSTEM.Status.IsError(status) { Do DecomposeStatus^%apiOBJ(%objlasterror,.Err) Write !,Err(Err) }
} }
...
When run produces:
Adding triggers to User.Titles User.Titles||TriggerOnInsert
<LIST>%Delete^%ooDictionary.TriggerDefinition.1
