How to Loop to Aggregate Columns?

How to Loop to Aggregate Columns?

  

Hi, I would like to loop through all the columns in the aggregate to compare if there was a change to each column. I would like to compare each column either using an index value [ i ]  where i is the index of the column.

Hope you can help me.

Thank you.

Solution

Hi Allan,

As far as I know there is no such possibility with the Platform, as columns are not directly exposed to the developer. You have the concepts of Entities (that will map to tables) and Attributes (that will eventually map to columns), but you cannot access them by index.

That being said, I'm curious, can you explain why you'd need such a pattern?

Solution

I would just like to make my life easier by looping into the columns and not going to type the name of the column one by one and compare if there was any changes made to specific column.

Anyway, thank you for answering my queries. Good day :)

Hi Allen,

To test whether there's any change in a record, you can just compare the records. But to test each attribute, you indeed need to "type the name of the column one by one" (although auto-complete makes your life easier here). If you really need a generic way, you could create an Extension that uses reflection to go through all the columns. A starting point for such an extension could be XML Records or SortRecordList since they already deal with Attributes in a generic way.

Search on forum for an extension DiffEntity or related posts. Now I am not getting it but this solves the problem.

Jorge Martins wrote:

Hi Allan,

As far as I know there is no such possibility with the Platform, as columns are not directly exposed to the developer. You have the concepts of Entities (that will map to tables) and Attributes (that will eventually map to columns), but you cannot access them by index.

That being said, I'm curious, can you explain why you'd need such a pattern?

Jorge

We are looking at the same pattern. We need to do generic validation on different columns of out entities with regular expressions i.e. if we capture contact details for a customer, we need to check the phone number, and postal code(zip code) for accuracy. We would like to create a generic table where we can use any entity and validate a column for correctness.

Any ideas on how to do this?


Hi Ruben,

You do not want to do this, because it would be maintenance hell. The "generic table" you mention would need to be 1:1 with the Entities and any change in them would break them.

Also, you should always perform input validation, and there should be no need for checking afterwards whether the data in the database is in the correct format, let alone that you'd want it on such a regular basis, you want some generic validation tables for it!

Kilian

This is input validation on the server side before the data is saved in specific cases. So I want the validation to be generic but will only call it when required. I manage to get around it by using the system tables. So I can pass an entity record to the 'validation', check is there is a regular expression setup for the attributes and then validate it.

Thanks for the response.

Hi Ruben,

I now see what you mean. Thanks for the additional info, and I think your solution would indeed be a kind of workaround for standard data types like e-mail and phone number.

Weird workaround.

Because you still dont know which validator you must use. So there will be another entity to hold the mapping from column to validator.

Cant see the advantage there.

Its just moving the configuration from developer to sys-admin...