web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Set Dynamic ranges for XDS policy

(1) ShareShare
ReportReport
Posted on by 493
I have a policy with SalesTable as primary table and created a query that has the same table as dataSource.. I didn't set any range in the query, Instead I override the init() method of the query and add my ranges in the code:
[Query]
public class DYNADDVSalesTableQuery extends QueryRun
{
    public void init()
    {
        QueryBuildDataSource qbds;
        QueryBuildRange qbr;

        super();

        qbds = this.query().dataSourceTable(tableNum(SalesTable));
        qbr  = qbds.addRange(fieldNum(SalesTable, SalesId));
        qbr.value('SO-0658823');
    }

}
but it didn't work! How could I make the policy use the query with my dynamic ranges?
I have the same question (0)
  • Waed Ayyad Profile Picture
    9,042 Super User 2025 Season 2 on at
    Hi,

    Can you add more details about your question? 
     
     
    Thanks,
    Waed Ayyad
  • AbdullahAhmed_ Profile Picture
    493 on at
    I hope you could help with this!
  • André Arnaud de Calavon Profile Picture
    301,321 Super User 2025 Season 2 on at
    Hi AbdullahAhmed,

    Can you tell about the exact conditions when a sales order should be visible (or editable) or not for a user? You now added a sales order hard-coded, but I think you can avoid having dynamic ranges using X++ coding, 

    In case you mention that "it didn't work", what is the current behavior? Do you get errors? Did you build the solution and synchronize the database? Also note that in case you have the system administrator role assigned, it will bypass all security, as well as the security policies.
     
    Note that you will not be able to send context to the init method of the query when using XDS. If you have rules and/or conditions, the query should be used to retrieve orders based on access permissions per user.
     
    So, please explain the conditions, then we can help you with a solution direction.
  • AbdullahAhmed_ Profile Picture
    493 on at
    Hii..
    I have a test user that I assign some roles for test and it's not admin at all..
    The scenario is that I have a form that admin can choose which field of sales table to set a range on and provide a value, and I read the field and the value from the related table to the form..
     
     
    I tried the simplest way and add a range in init method with a value but it's not working..
    by saying it's not working I mean the normal behaviour that the user can see all sales orders and I want to restrict this.
  • Verified answer
    André Arnaud de Calavon Profile Picture
    301,321 Super User 2025 Season 2 on at
    Hi AbdullahAhmed,

    The XDS framework is not executing the query. It will be used to get the ranges and possible joins to add to the form data source or any select statement just before trying to retrieve records from the database. So I think the init method will never be executed by XDS. 

    You can create a MyConstruct table, which is temporary table. In this table you can add a XDS method where you can use X++ to fill a temporary table per user. You can look at several tables in the AOT starting with 'My"  (e.g.  MyDepartmerns) to check how to create such table and insert records.
     
    Using X++ you can insert records with a reference to the sales order table to be able to filter the records for the user. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 678 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 394 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 281 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans