Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

XDS Security issue

Posted on by 922

Problem: I want to set XDS Query in such a way that when it found zero rows it should return all possible values.

Details:

I got a requirement to have a single security Role to work with multiple security policies. 

Each policy got an especial column in custom security table from where it gets its parameters for XDS Query. Custom security table is a custom table which is like matrics to assign different warehouse, itemgroup etc to different users

Till now everything working fine. Now the client wants that if now warehouse is assigned to a user all warehouse data should be shown instead of no data. 

Is there any way I can achieve this by changing the XDS query to get all the record if no warehouse or itemgroup is assigned in the security table.

  • Suggested answer
    Khurshid Wali Profile Picture
    Khurshid Wali 922 on at
    RE: XDS Security issue

    Thank You Andre and ievgen,

    I am able to set XDS Security Role successfully  for the first time.

    I figure out that As I am using invent table as primary table in security policies.  I was not getting any result when I use the above code with policy enabled..

    Here is the final Xds Method.

    Please suggest any changes to improve performance

    public RefreshFrequency xds()

    {

       UserId  currentUser =curUserId();

       MyWarehouseForXDS myWarehouseForXDS;

        UserSecurityDocuments userSecurityDocuments;

       InventLocation inventLocation;

       XDSServices xdsServices=new XDSServices();

        UserConnection                      c=new UserConnection();

       ;

       myWarehouseForXDS.setConnection(c);

       select userSecurityDocuments

          where userSecurityDocuments.UserId             == currentUser

               && userSecurityDocuments.InventLocationId   != '';

       if (userSecurityDocuments.RecId!= 0)

       {

           userSecurityDocuments.clear();

           c.ttsbegin();

         insert_recordset MyWarehouseForXDS(InventLocationId,UserId)

           select

           InventLocationId, currentUser

           from usersecuritydocuments

           where usersecuritydocuments.userid             == currentUser

               && usersecuritydocuments.inventlocationid   != '';

           c.ttscommit();

       }

       else

       {

           XDSServices.setXDSState(0);

          c.ttsbegin();

           insert_recordset myWarehouseForXDS(InventLocationId,UserId)

               select

               InventLocationId, currentUser

               from inventLocation

               group by InventLocationId;

           c.ttscommit();

           XDSServices.setXDSState(1);

       }

       return RefreshFrequency::PerSession;

    }

  • Khurshid Wali Profile Picture
    Khurshid Wali 922 on at
    RE: XDS Security issue

    Sorry, I thought it is latest version R3 of Ax2012.

    I am using temp table.

    I am not getting any result when it is set to  return RefreshFrequency::PerSession;

    But getting result for perinvocation.

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: XDS Security issue

    And the next one on your screenshot is current version that is Dynamics 365, that's why I said that it is confusing.

    Do you have temp or regular table ?

  • Khurshid Wali Profile Picture
    Khurshid Wali 922 on at
    RE: Ax2012 XDS Security issue.

    Thank you Andre,

    Here is the code

    I have keep it simple.

    public RefreshFrequency xds()

    {

       UserId                   currentUserId = curUserId();

       InventLocation inventLocation;

       MyWarehouseForXDS myWarehouseForXDS;

       ;

       insert_recordset myWarehouseForXDS(InventLocationId)

       select

           InventLocationId

       from inventLocation

       group by InventLocationId;

       return RefreshFrequency::PerSession;

    }

  • Khurshid Wali Profile Picture
    Khurshid Wali 922 on at
    RE: Ax2012 XDS Security issue.

    5852.Capture.JPG

    Dear ievgen,

    I have corrected the tags and it is clearly written ax 2012.

  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 290,537 Super User 2024 Season 2 on at
    RE: Ax2012 XDS Security issue.

    Hi Khurshid,

    If you make it a regular table, then it is not considered anymore to execute the xds() method. So, you have to keep it as temporary. You can share the coding of the XDS() method or debug yourself. See also another blog how to do debugging when logging on as a normal user: kaya-consulting.com/tips-on-ax-2012-security-development-tool-part-6

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Ax2012 XDS Security issue.

    First of all you need to start from the version, you did not correct your tags so we have to guess if its 2012 or D365. Then give us some detail about query you have, mywarehouseXDS table properties  and code in XDS  method.

  • Khurshid Wali Profile Picture
    Khurshid Wali 922 on at
    RE: Ax2012 XDS Security issue.

    Thank You ievgen for detail explanation,

    I setup a temp table with the same properties as myaddressbookxds (default table) and xds method.

    But it is not working as expected. How can I debug? I am not getting anything in mywarehouseXDS (temp table) (after I made it regular just to test it is blank).

    XDS method is not invoking.

    Please help me with any documentation.

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 290,537 Super User 2024 Season 2 on at
    RE: Ax2012 XDS Security issue.

    Hi Khurshid,

    You can actually have a look at an example I did create in the past to secure by warehouse. It is then also filling an XDS construct table with allowed warehouses, but different compared to your requirement. Anyway, you can possibly learn from it: kaya-consulting.com/extensible-data-security-examples-secure-by-warehouse

  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Ax2012 XDS Security issue.

    Ok, let me try again, you obviously decided not to read anything.  You have AOT query that returns all available warehouses for a user and you use it in the policy. I assume that you have setup table that has warehouses available for a user and you use it in that query. Solution is to remove setup table from the query completely, create new temp table "MyWarehouses", define xds() method on it. In that method populate "MyWarehouses" with available warehouses for current user (take them from the setup table if it is not empty for current user; otherwise insert all). Use "MyWarehouses" in AOT query.

    That white paper talks about xds() method and RefreshFrequency and other things you need to know, but literally AX triggers that method for each user, so each user could have it's own data set and you can put X++ code to populate this data set in a way you like for each 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

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,537 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,520 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans