Make the field "Unit Price" in page Sales Order Subform editable regarding the current user ?

Maddynav123Maddynav123 Member Posts: 12
Hi guys,

Please can you help me how make the field "Unit Price" in page Sales Order Subform editable regarding the current user with C/AL ?

Thank you.

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Can you express more clearly what do you want to achieve?

    Every user logged to the system and using it is the "current user£, so if you want to make it editable for "current user" it means it should be editable for everyone.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Maddynav123Maddynav123 Member Posts: 12
    In table 91 User Setup I added a new field Allow Editing Unit Price (type Boolean) and also I create a function in table 91 that returns the value of the new field if the record exists for the current user, or FALSE if the record not exists.

    IF "User ID" <> '' THEN BEGIN
    IF UserSetup.GET(USERID) THEN BEGIN
    AllowEditingUnitPrice := UserSetup."Allow Edit Unit Price";
    EXIT(AllowEditingUnitPrice);
    END;
    END;
    EXIT(FALSE);

    In page 46 Sales Order Subform I shpuld make the field Unit Price editable regarding the current user setup for the new field. This is what I am trying to do.
  • JuhlJuhl Member Posts: 724
    edited 2018-04-28
    Use permissions if user can or cannot edit Item.
    Follow me on my blog juhl.blog
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Editable is no longer available on pages as a field property which can be changed at a runtime. You can make the entire subpage editable or not during runtime, but not an individual field.

    You can get desired effect by adding a code throwing errors in Unit Price - OnValidate trigger on the page
    UserSetup.GET(USERID) ; //will thow an error if user does not have UserSetup therefore no explicit permission are definied
    UserSetup.TESTFIELD("Allow Edit Unit Price", TRUE); 
    
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Maddynav123Maddynav123 Member Posts: 12
    Thank you Slawek,

    I add the code in Unit Price - OnValidate on Page.46 Sales Order Subform but again I can't edit it.

    What can I do ?
  • krikikriki Member, Moderator Posts: 9,112
    [Topic moved from 'NAV Tips & Tricks' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DrakonianDrakonian Member Posts: 14
    edited 2018-05-27
    The function is on the subform? The design of your solution is not quite clear.
    Also, i suggest this soulltion. Add on subform new Boolean variable. And make code like this:
    OnOpenPage
    UserSetup.GET(USERID);
    
    OnAfterGetCurrRecord
    NewBoolean := UserSetup."Allow Edit Unit Price";
    

    Then add variable NewBoolean in editable property "Unit Price" on subform.
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Adding UserSetup.GET(USERID) in OnOpenPage will result in blocking opening Sales Order form for anyone not having UseSetup rec defined. That's not the original requirement.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • DrakonianDrakonian Member Posts: 14
    edited 2018-05-27
    So he can do
    OnOpenPage
    IF UserSetup.GET(USERID) THEN;
    

    For get record only once without error.
  • Maddynav123Maddynav123 Member Posts: 12
    Hi,
    First of all thank you for your support.

    My finale version so far is:
    - In T.91 User Setup I add a new field "Allow Edit Unit Price"-> Boolean
    - In T.91 User Setup I create a new function: AllowEditingUnitPrice() : Boolean

    AllowEditingUnitPrice() : Boolean
    IF NOT GET(UPPERCASE(USERID)) OR (USERID = '') THEN
    EXIT(FALSE);
    EXIT("Allow Edit Unit Price");

    - In Page 46: Sales Order Subform I did the following:

    Unit Price - OnValidate()
    UserSetup.GET(USERID);
    UnitPriceEditable := TRUE;
    UnitPriceEditable := UserSetup.AllowEditingUnitPrice;

    PS: In the properties of Field Unit Price I make:
    Editable : UnitPriceEditable

    When I run the page, field "Unit Price" ( Which is shown as "Unit Price Excl. VAT" isn't Editable. I am using NAV 2017

    Please what you advise me to do?

    BR
    MADDY
  • DrakonianDrakonian Member Posts: 14
    edited 2018-05-28
    Function will return AllowEditingUnitPrice FALSE or value from field? But by default boolean fields returns false. And i don`t understand why you GET userID in UserSetup, if it is part of primary key and he will always be present.

    Code on trigger OnValidate work only after value changed. So variable UnitPriceEditable = FALSE.
    I would say that there is a lot of redundant code here. Function AllowEditingUnitPrice doesn't look necessary.

    My solution for you:

    In T.91 User Setup I add a new field "Allow Edit Unit Price"-> Boolean

    On page 46 Sales Order Subform
    OnOpenPage
    IF UserSetup.GET(USERID) THEN
      UnitPriceEditable := UserSetup."Allow Edit Unit Price";
    

    Add variable UnitPriceEditable in editable property.

    So when you do not get userid in UserSetup, field will be NotEditable because boolean field by default return FALSE. Otherwise code will check in UserSetup value from field "Allow Edit Unit Price" and will replace.
  • Maddynav123Maddynav123 Member Posts: 12
    I must create a function in table 91 that returns the value of the new field if the record exists for the current user, or FALSE if the record not exists.

    Is underlined for my issue.
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2018-05-28
    A boolean field in an uninitialized record variable (or more generally uninitialized boolean var) in NAV defaults to FALSE. After calling IF UserSetup.GET(USERID) THEN; added field "Allow Edit Unit Price" will be FALSE if UserSetup does not exist for a given USERID
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.