Can you run a criteria search through a database/table using pseudo attributes with Granta MI Python Scripting Toolkit 2.3 ?
For example finding all records within a given table that have been modified in the last 24 hours.
This is possible but the approach is slightly different than searching on Attributes. In a future version we intend to make this more discoverable.
The approach is to create a SearchCriterion object directly, this can then be passed to table.search_for_records_where as normal.
SearchCriterion
table.search_for_records_where
import granta as mpy from datetime import datetime, timedelta s = mpy.Session('mi-server', autologon=True) db = s.dbs[0] table = db.get_table('TableName') now = datetime.now().strftime("%Y-%m-%dT%H:%M:%S") early = (datetime.now()-timedelta(hours=48)).strftime("%Y-%m-%dT%H:%M:%S") ref = mpy.PseudoAttributeDefinition('modifiedDate') val = (early, now) sc = mpy.SearchCriterion(ref, 'BETWEEN', value=val) recs = table.search_for_records_where([sc]) print(recs)
There are a few things to note here:
datetime.datetime
PseudoAttributeDefinition
The documentation does not make clear exactly which Pseudoattributes can be searched on, for the moment the list is below for reference. Only the Pseudoattributes listed below the search criterion can be searched with that criterion, and only those criteria support searches on Pseudoattributes.
BETWEEN
CONTAINS
CONTAINS_ANY
EQUALS