SBX - Search With Button

SBX - Forum Post Title

How to add access level to privilege with code?

Microsoft Dynamics AX Forum

BASMA asked a question on 2 Oct 2018 4:04 AM
My Badges

Question Status

Suggested Answer

Hi,

I want to get the access level of privilege with code :

I want to add switch case statement to my code : How can I declare the  value of access level in the statement?

Reply
Vilmos Kintera responded on 2 Oct 2018 4:10 AM
My Badges
Suggested Answer

AOT > System Documentation > Enums > AccessRight has those options I believe.

So you can do it via the AccessRight enum.

But to be sure you could check the enumeration behind the SecurityPermission tables' Access field where this information is stored, using reflection (Dict* classes like DictEnum maybe?)

Reply
BASMA responded on 2 Oct 2018 4:25 AM
My Badges

Sorry I don't understand your suggestion:

in AccesRight :NoAccess,View,Edit,Add,Correction,Delete.

in AccessLevel of privilege:NoAccess,Read,Update,create,correct,delete.

Can I do like this??

switch(_node.AOTgetProperty(#AccessLevel))

       {

           case AccessRight::Add:

            eukSecTreeNode.SecurityLevel=EUKSecurityLevel::Delete;

       }

Reply
Vilmos Kintera responded on 2 Oct 2018 5:15 AM
My Badges
Suggested Answer

Yes.

And here is what I have explained above:

static void Job1(Args _args)
{
    info(strFmt('%1',
        enumId2Name(
            new DictField(
                tableNum(SecurityPermission),
                fieldNum(SecurityPermission, Access))
            .enumId()))
        );
}
Reply
Vilmos Kintera responded on 2 Oct 2018 5:21 AM
My Badges

Also in the code that you took a screenshot of above, you are using a TTS block around an insert, which is not necessary, unless you want to catch errors like a duplicate key exception.

Reply
BASMA responded on 2 Oct 2018 5:23 AM
My Badges

I have errror when I compare AccessLevel with AccessRight :

switch(_node.AOTgetProperty(#AccessLevel))

      {

          case AccessRight::Add:

           eukSecTreeNode.SecurityLevel=EUKSecurityLevel::Delete;

      }

Reply
Vilmos Kintera responded on 2 Oct 2018 5:26 AM
My Badges
Suggested Answer

Because you are comparing a string value against an enumeration. Typical apples to bananas situation, the error message is very clear about this.

Convert it to a proper enum value.

Reply
Vilmos Kintera responded on 2 Oct 2018 4:10 AM
My Badges
Suggested Answer

AOT > System Documentation > Enums > AccessRight has those options I believe.

So you can do it via the AccessRight enum.

But to be sure you could check the enumeration behind the SecurityPermission tables' Access field where this information is stored, using reflection (Dict* classes like DictEnum maybe?)

Reply
Vilmos Kintera responded on 2 Oct 2018 5:15 AM
My Badges
Suggested Answer

Yes.

And here is what I have explained above:

static void Job1(Args _args)
{
    info(strFmt('%1',
        enumId2Name(
            new DictField(
                tableNum(SecurityPermission),
                fieldNum(SecurityPermission, Access))
            .enumId()))
        );
}
Reply
Vilmos Kintera responded on 2 Oct 2018 5:26 AM
My Badges
Suggested Answer

Because you are comparing a string value against an enumeration. Typical apples to bananas situation, the error message is very clear about this.

Convert it to a proper enum value.

Reply

SBX - Two Col Forum

SBX - Migrated JS