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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Answered

Is it possible to create an XDS Policy query in code

(0) ShareShare
ReportReport
Posted on by 1,673

Hi everyone

When you create an XDS policy, you need to create a query for it as well. Usually you'd create this query in the AOT.

However, sometimes a query is too difficult to create in the AOT and easier to create in code.

Is it possible to create a query in code and then use it in an XDS policy?

If so, how?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    André Arnaud de Calavon Profile Picture
    301,053 Super User 2025 Season 2 on at

    Hi Brandon,

    It is not possible to use runtime queries as input for XDS policies. Possibly, you are looking for an easy way to control the outcome of a query? If so, you can use the so called "MyContruct" tables to collect data using x++ which fills a temporary table with user specific data. Have a look at one of my XDS examples which is using such MyConstruct table: dynamicspedia.com/.../extensible-data-security-examples-secure-by-retail-channel

  • BrandonSA Profile Picture
    1,673 on at

    Thank you Andre

    Implementing an XDS method on a temp table worked. However, with regards to the XDS method that you implement on a temp table, have you ever had concurrency issues?

    I've created a policy based on the workflow status of a Purchase Order. Everything works fine except when I try to approve a purchase order with the user who has the policy imposed on them.

    When this user tries to approve the PO, I get a suspended query. SQL performs a count on the temp table, and then tries to truncate it. This truncate call gets suspended.

    When I use the trace parser, it looks like an SQL cursor or holding on to the temp table, or at least onto PurchTable (which is the constrained table). I think the cursor is triggered by a queryRun.next() call.

    Obviously you wouldn't be able to know what the solution is to this or what the problem is based on the little bit of information I've given here, so I just want to check if you've ever come across anything similar, or if you do know of any concurrency issues or hotfixes etc?

  • André Arnaud de Calavon Profile Picture
    301,053 Super User 2025 Season 2 on at

    Hi Brandon,

    I have not seen this behavior, but had seen a scenario where the AOS crashed due to a very rare combination of calls. Can you tell a bit more about your policy? What does the query look like, what is the main constrained table, on what level is this PO constrained? How many records do you have in the purchase order table and how many records do you have in the temp DB? Is the temp table set to run on the TempDB database? What exact version of AX are you using?

  • BrandonSA Profile Picture
    1,673 on at

    Hi Andre

    Thanks for the reply. The more I've studied up on this, the more puzzling it gets. My policy is simple.

    It's Ax2012 R3, CU9

    The query is simply PurchTable joined to MyTemp on PurchId, exists join

    MyTemp is of type TempDB, not InMemory. It consists of PurchId only

    The policy is role based, Enabled, Constrained Table set to Yes, Primary Table is PurchTable, Operation is Select (although none of the other options work either)

    The xds method is simply:

    xdsServices.setXDSState(0);
    insert_recordset purchTableForXDS(PurchId)
    select PurchId from purchTable
        join hcmWorker
        where purchTable.WorkerPurchPlacer == hcmWorker.RecId
            join dirPersonUser
            where hcmWorker.Person == dirPersonUser.PersonParty
                && dirPersonUser.User   == curUserId();
    xdsServices.setXDSState(1);
    At different times, an SQL statement is trying to truncate the temp table. It's always preceded with a count. The truncate gets suspended.
    Right now, it happens even when I try to create a PO with the constrained user. The user has a couple of PO related roles, and the role I created for this policy.

    Thanks

  • AbdullahAhmed_ Profile Picture
    444 on at
    Can someone explain the solution in simpler way?
    The Tmp table has 1 or 2 fields but the final result that shows on the form should show all fields?

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

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans