Question
· 21 hr ago

Modifying the value of a variable OnSqlTrigger - TrakCare

Hi everyone, 

This is the first time I'm dealing  with a request of modifying a variable value in a UDF OnSQLTrigger on InterSystems TrakCare.

I can't find any documentation to address this issue, but basically, my goal is to modify the value of one of the fields in a table when it is first inserted. 

This is basically what the code should do, namely, to change the content of the %d variable at a specific key. 

I have done quite a bit of debugging and seen that the %d has been correctly modified after I set %d(51) = <something>, but the value saved in the database it is still the original %d(51) value.

ClassMethod ModifyOnSQLTrigger() As %Status
{
    Set sc = $$$OK
    Try {
        If %oper="INSERT" {
            Set %d(51) = 1
        }
    } Catch ex {
        Set sc=ex.AsStatus()
        Do ex.Log()
    } 
    Return sc
}

Actually, I don't know if what I would like to do is technically possible. If it isn't, do you have any workaround? 

Any suggestions are welcomed :)

Thanks!

Discussion (4)2
Log in or sign up to continue

There are a few items to consider with the example above:

  1. I would expect that UDFs are being triggered through the "Features Framework" which acts as a "wrapper" of sorts for User Defined Functions. It allows us to define multiple methods for a class and event which can be enabled or disabled based on site requirements. If you're adding calls to websys.UserDefinedFunctions and the Features Framework is enabled, you will lose the manually added call next time a patch is applied.
  2. The features framework explicitly protects %d and %old so they cannot be overwritten or modified inside an SQL trigger as doing so can have unpredictable results - a large number of TrakCare classes use SQLStorage.
  3. We need to know what you're trying to achieve. There are a couple of approaches to setting default values like this.
  4. UDFs return %Boolean values, not %Status codes.

Hi Pietro,

%d should not be modified as it might impact down the road triggers especially for TrakCare.

As i don't know what you are trying to achieve its difficult to advise directly.

For TC i usually would use a different trigger namely OnBeforeSave / OnAfterSave which will trigger based on user activity from the UI or on Object saves. Using those you could modify the value to be saved or update after it already has been persisted. 

Maybe best to request assistance from support for your specific issue.

Best Regards
Timo