RecordClear Action

Service Studio
On our radar
Like ListClear action there should be one for records.
With just one action and just passing the record name as argument it could set the record attributes to the default values. 

This would be easier, faster and much cleaner than setting all attributes one by one or assigning the record to a blank one. 
Created on 11 Mar 2015
Comments (5)
I learned this the hard way, turns out that assigning a blank record doesn't work so well when iterating over a record list in a loop, record assignments are by reference, not by value!

J.JA, though this is maybe not the right place to discuss it, record assignments are definitely not by reference. Record list assignments are, perhaps you are mixing them up? We have dozens of for eaches in our code that use an empty record to assign to the one that's used to ListAppend to a list that's build.

As for the original idea, the problem would be that records are passed by value, so you can't have an actual Action to clear a record. Under the hood the default values of a record are part of the record's constructor, so you need to create a new one and assign that to the old one to clear the old one. But it would be nice to be able to have an easier way than to do it manually, even if I can't think of a good way to implement it on a functional level that's technically also possible.
Kilian -

You're right... in this case, what messed us up was that the record contained an Attribute of type Record List... that's what was getting messed up... been a long week!


Internally the RecordClear action could create a new instance of the object and assign it to our existing variable. Or, .NET has the default keyword that coud also be used for this case:

Still, you'd need to assign the record to the clear function that has the record as parameter. That could work, but looks a bit odd.