C/AL code for specific user

I need only specific user to update the sales price.In the user setup table i have created a boolean .only the person with that boolean tick can update the sales price.how to write c/al code for this?
thanks
gugan

Answers

  • guganvarman_21guganvarman_21 Posts: 13Member
    please answer its emergency
  • KlappspatenKlappspaten Posts: 19Member
    edited 2019-10-09
    In the beginning of the OnValidate trigger of the field, get the User Setup Record for the current user
    UserSetup.GET(USERID)
    
    Then check if your new boolean field is activated, if it's not throw an error.
    IF NOT UserSetup."Boolean Field" THEN
        ERROR('Your text as textconstant here')
    

    Remember to create a local variable of type Record and Subtype 91 (User Setup Table) for this purpose.
  • guganvarman_21guganvarman_21 Posts: 13Member
    Thanks Klappspaten.
    There are 4 users in the user set up and i need only particular users to update the price.In that case how can i give privilege to that users alone
  • KlappspatenKlappspaten Posts: 19Member
    edited 2019-10-09
    This way you did it.
    The code I provided does the following:

    1. The OnValidate trigger of the price field is invoked
    2. Get the User Setup Record for the user which invoked the trigger
    3. Check if the user has the priviledge to change the price
    4. The user has no priviledge/flag? Throw an error.

    If you need to give other users the priviledge to modify the price, or want to remove the priviledge for a user, activate(deactivate your new boolean field at User Setup for this user.
  • krikikriki Posts: 8,836Member, Moderator
    [Topic closed because of double posting]
    See https://forum.mibuso.com/discussion/74318

    Regards,Alain Krikilion
    Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
This discussion has been closed.