Searching on "Date Modified" property returns records from other tables

Options
Clay Records
Clay Records Member Posts: 3
Photogenic First Comment
edited May 28 in Materials

When I perform a search for records in a table that have the "Modified Date" property between two dates, records from tables other than the one used for the search are returned. The mistaken records' .table property incorrectly list the selected table.

def get_recently_modified_records(
    table: granta.Table,
    minimum_date: str,
    maximum_date: str,
) -> list[granta.Record]:
    utils.logger.info(
        f"Getting records modified between {minimum_date} and {maximum_date}"
    )
    modified_criterion = granta.SearchCriterion(
        granta.PseudoAttributeDefinition("modifiedDate"),  # type: ignore
        "BETWEEN",
        (minimum_date, maximum_date),
    )
    return table.search_for_records_where([modified_criterion, table_criterion])

Adding a new criterion for the table returns an error stating that the table name psuedo attribute cannot be used for searching.

table_criterion = granta.SearchCriterion(
        granta.PseudoAttributeDefinition("tableName"),  # type: ignore
        "CONTAINS",
        table.name,
    )
Tagged:

Answers

  • Chris Harrold
    Chris Harrold Member, Administrator, Employee Posts: 169
    First Answer First Comment First Anniversary Ansys Employee
    admin
    Options

    @Doug Addy - this is actually a Granta Q - I have added tags, but can you assist?

  • Andy_Grigg
    Andy_Grigg Member, Employee Posts: 27
    Name Dropper First Answer First Comment First Anniversary
    Options

    Hi Clay. This should be resolved in Scripting Toolkit v4.0, released with MI 2024 R2. Searching a table with a pseudo-attribute-based criterion now only returns results from that table.

  • Clay Records
    Clay Records Member Posts: 3
    Photogenic First Comment
    Options

    Thank you, Andy!
    Does STK v4.0 work with Granta MI 2024 R1?

  • Daniel Manocchio
    Daniel Manocchio Member Posts: 22
    5 Likes First Comment Photogenic
    edited 6:54AM
    Options

    Hi Clay,

    As a quick workaround for this issue you could add a "dummy" search criterion for an attribute that is always populated, like tb.attributes["ATTRNAME"].search_criterion(exists=True).
    For me, the search_records_where()-method then only returns records from the correct table. At least until STK4.0 is released :-)

    Hope this helps & bests,
    Daniel

  • Andy_Grigg
    Andy_Grigg Member, Employee Posts: 27
    Name Dropper First Answer First Comment First Anniversary
    Options

    @Clay Records said:
    Thank you, Andy!
    Does STK v4.0 work with Granta MI 2024 R1?

    Yes, 4.0 will be backwards compatible as far as 2023 R1