In Designer mode

 


Let us correct the access restriction.

  1. Return to Designer.

    To prevent viewing the document, you have to edit the data access restriction.

    The new condition will be more complex, so we will also demonstrate how you can use templates in data restrictions.
  2. Open the Technician role and click the Templates tab (fig. 22.21).


    Fig. 22.21. Adding an access restriction template to the Technician role
  3. Add a template named BonusIncluded, with the text shown in listing 22.2.

    Listing 22.2. Data access restriction

    SELECT
        1
    FROM
        Document.EmployeeAccruals.Accruals
    WHERE
        Document.EmployeeAccruals.Accruals.CalculationType =
            VALUE (ChartOfCalculationTypes.MainAccruals.Bonus)
            AND Document.EmployeeAccruals.Accruals.Ref = #Parameter(1).Ref
    Actually it is a query to the tabular section of the EmployeeAccruals document, which returns either nothing or a single-field record that contain 1 as its value.

    This record is returned if the document tabular section includes the Bonus calculation type.

    The second condition in the query specifies the document whose tabular section is accessed. This condition uses a template parameter.

    Listing 22.3. Data access restriction

    AND Document.EmployeeAccruals.Accruals.Ref = #Parameter(1).Ref
    #Parameter(1) will be replaced with the string specified when this template is called from the data access restriction.
  4. Return to the Rights tab.
  5. In the access restriction for other fields (the first row) replace the restriction with the text shown in listing 22.4 (fig. 22.22).

    Listing 22.4. Data access restriction

    DocAccruals WHERE NOT 1 IN (#BonusIncluded("DocAccruals"))

    Fig. 22.22. Setting an access restriction for the Technician role

    The #BonusIncluded("DocAccruals") statement calls the template. The template script is simply inserted here and the DocAccruals line replaces the first template parameter (#Parameter(1)).

    As we have mentioned earlier, if a tabular section includes an accrual named Bonus, the query in the template returns a single record with 1 as its value.

    This is why the condition shown in listing 22.4 allows reading DocAccruals when the template query does not return 1:

    ... WHERE NOT 1 IN (#BonusIncluded("DocAccruals"))
    So it happens when the tabular section does not contain any Bonus accrual.

    You could specify this restriction condition directly, without using a template. But the resulting script would have been more complicated (listing 22.5). And templates also provide the option to separate some parts of restriction conditions for reuse in other conditions.

    Listing 22.5. Data access restriction

    DocAccruals WHERE NOT 1 IN (
        SELECT
            1
        FROM
            Document.EmployeeAccruals.Accruals
        WHERE Document.EmployeeAccruals.Accruals.CalculationType =
            VALUE(ChartOfCalculationTypes.MainAccruals.Bonus)
            AND Document.EmployeeAccruals.Accruals.Ref = DocAccruals.Ref)
  6. Close the rights editor.

Comments
0
Add comment