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.
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.
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);
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.
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.
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:
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.
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.
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
Answers
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.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
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.
You can get desired effect by adding a code throwing errors in Unit Price - OnValidate trigger on the page
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
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 ?
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Also, i suggest this soulltion. Add on subform new Boolean variable. And make code like this:
Then add variable NewBoolean in editable property "Unit Price" on subform.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
For get record only once without error.
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
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
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.
Is underlined for my issue.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03