How to implement compilcated filtering to business entity?
 
Forums / SmartComponent Library - Developer Forum / How to implement compilcated filtering to business entity?

How to implement compilcated filtering to business entity?

3 posts, 1 answered
  1. Toni Perätalo
    Toni Perätalo avatar
    7 posts
    Registered:
    08 Feb 2019
    Answered
    28 Mar
    Link to this post
    Hi,
    I have following use case: I have created a business entity for purchase invoices that fetches invoices and lines from the database. Now I need to add filtering that when users browse (fetch) purchase invoices they must only see the invoices they are allowed to. Rules that apply are rather complicated and cannot be written directly to dataset/datasource query.

    So in non-business entity world we could just write:
    FUNCTION CanView RETURNS LOGICAL (INPUT iPmtNum AS INTEGER):
       // do some complicated validation from several tables and temp table, uses CAN-FIND statements etc.
       RETURN xCanView.
    END FUNCTION.

    FOR EACH Payment NO-LOCK WHERE ...:
       IF NOT CanView(Payment.PmtNum) THEN NEXT.
       CREATE ttPayment.
       ....
    END.

    Question: Is there a way to implement this to Business Entity (data access level) or is the only way to implement business task for that?

    Regards,
    Toni
  2. Mike Fechner
    Mike Fechner avatar
    352 posts
    Registered:
    14 Sep 2016
    28 Mar in reply to Toni Perätalo
    Link to this post
    The typical place for that kind of row-level security would be the BEFORE-ROW-FILL callback in the Data Access class. The DB record is already available and this is before the TT record is created. 

    If you want to reject a row, you RETURN NO-APPLY.

    Downside is, that the count request is not using those call-backs, as the count request, just looks at the number of records returned by the query. So you will have to manipulate the count record result yourself. 
  3. Toni Perätalo
    Toni Perätalo avatar
    7 posts
    Registered:
    08 Feb 2019
    28 Mar in reply to Mike Fechner
    Link to this post
    Thank you Mike! I was thinking too complexly :) And I was investigating the BEFORE-FILL callback.
    Yes, I need to manipulate the count record result too.

    Cheers,
    Toni
3 posts, 1 answered