Dynamic return value of an expression or a cachevalue

Hi,

In a component I retrieve all records in my database using this expression:

{novulodatastructuretypes,modelname, true, modelname.asc}

I have a datetime set at my general settings and I have an expression that then checks for all recordtypes found in our database, if it has been createdat or modifiedat since the given datetime (i.o.w. these records are new or have been changed).

trigger.recordtype.concat(":exists({").concat(trigger.recordtype).concat(",this,boolean:or([modifiedat.isgreater(datetime:first({generalsettings,data_changed_since_datetime})),createdat.isgreater(datetime:first({generalsettings,data_changed_since_datetime}))])})")

For each recordtype that I’ve found I then want to query the database to retrieve all records that have indeed been changed. For example: I’ve found that the products table has multiple changed records. To retrieve these, I need to be able to somehow set the expected result type dynamically, based on the recordtype for which we are currently querying.

Is this somehow possible?

Hey Joeri,
Very interesting question, I also want to know :slight_smile:
If I understand correctly, you want to know whether any record of a dynamic type exists that was modified or created after a specific date time, regardless of which exact records.

I built component M10893 for you, but I haven’t tested it yet.
The process “RecordTypeString - Has modified records after date time (experimental)” can be consumed in your component.
Please let me know if it works or if it doesn’t so that I can remove the experimental status or deprecate the process.

  1. recordtype and datetime should be input parameters. I know that you want to use the date from the general settings for the date time. Just use it as the parameter when calling the process. This way the date time is only retrieved once which saves 1 SQL query and the process becomes more generic.
  2. Cache the expression you want to execute as a string. I removed the “exists” part from your initial expression because I am not sure if it would work. The expression should retrieve a list of all of records modified/created at after the given date time.
  3. Put the cached expression string into the “evaluate expression” action from the ExpressionTools Plugin. Configure the expected result type to List<Mixed>. This is the part where I am not sure if it would work. @m.gechev probably knows.
  4. Put the List<Mixed> into a for each. The foreache happily handles List<Mixed> without throwing type errors.
  5. If the list is empty, then the “Do” branch is skipped and the “End” is executed immediately. So in that case, we can return “has_records = false”. However, if the list is not empty, the for each will enter the “Do” branch. Instead of actually doing something, we will return “has_records = false”

As I said, I am not 100% sure that this will work. You might get a type error at step the “EvaluateExpression - List<Mixed>

Hi Joachim,

What you’ve built in that component is what I already have in my component. I want to do something that comes after knowing that there are indeed records that have been changed.

For example: you’re process finds that the table products has records which have been created or edited since given datetime. I then want to query these actual specific records.

You would simply do the same expression, but then use a cachevalue. You then need to somehow dynamically determine the result type of the cachevalue. That is my question. Is this possible somehow?

Hey Joeri,

No, I do not know of a similar to a cache value action where you can set the record type dynamically. What is your intention further down the line?

What do you exactly mean by

“I then want to query these actual specific records”

In step 3 a list of all records is “queried” and stored in a list mixed.

Regards
Joachim

Do you mean that you want to process each of the records individually?
I can only guess that you want to store in the application which records have changed so that you can do some health checking/exporting etc.

Is that correct?

The only thing that I can think of that could help is that you add a few extra steps to the “Do” branch of the “for each” (4). I would create a new record to track all mutations of any record after a specific datetime. For example:

N_RecordMutation
Record_reference_type: STRING
Record_reference_id: INT
Was changed after: datetime

Build a process similar to “Application log - Write log with dynamic record reference” in M6615 and add it to the “Do” branch of the for each. At a later stage you can process all “N_RecordMutation” records and process the linked records. You might also need to build a function is_linked_to_record(record to compare with) on the N_RecordMutation.

Exactly what you said is what I’m trying to achieve. I want to to individuallt process the records.

Maybe that process will help, I will check!

Good luck. Let me know if it works, sounds like a cool project :slight_smile: