- Log in to post comments
Ah. Thanks for clarifying. That makes a bit more sense now but also raises another question. Are you creating the questionnaire through an API call, or is the questionnaire being added/updated as a result of an API call to a different component? If it's the former, you should just be able to populate the property when it's created.
I can't think of any reason why OnBeforeSave wouldn't fire in any case. I can have a look on Monday when I'm in front of my work computer. I've done similar to what you're trying to do and I would usually set a flag using a PPG in OnBeforeSave if %request.Data("ID",1)="" and then check that in the OnAfterSave and update the item then. Alternatively if there's no ID (like above), you could set %request.Data(<component item name>,1) = 1 in OnBeforeSave and the %request value would be used when it populates the object values to save.
- Log in to post comments
There are a few items to consider with the example above:
- 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.
- 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.
- We need to know what you're trying to achieve. There are a couple of approaches to setting default values like this.
- UDFs return %Boolean values, not %Status codes.
- Log in to post comments
That's correct (although from your example I would use $get(%request.Data("Q31",1)) over the "Get" method). I had another look and an assumption I had made in my previous post was partially incorrect. At least in questionnaires you can safely check the IsNew property of %UDF - this is correctly set when a questionnaire is created using either an API or through the UI. This value is derived from a variable that is set at the very top of the save so it allows us to identify a new added record. Here is a fairly simple (if a little crude) example:
As you can see, the value of "Q01" is only set to "N" on the first save and is not updated afterwards.