Sometimes it might be requested that specific users should not be able to change their work date.
This could be achieved by a simple per tenant extension (PTE). Below the relevant code
The code below is related to version 14.x but it could be easily applied also to higher versions.
Create a table extension that extends User Setup table
tableextension 50110 "UserSetupTableExt" extends "User Setup"
{
fields
{
field(50110; "Change Workdate"; Boolean)
{
Caption = 'Change Workdate';
DataClassification = ToBeClassified;
}
}
}
Create a page extension that extends User Setup list
pageextension 50110 "UserSetupListExt" extends "User Setup"
{
layout
{
addlast(Control1)
{
field("Change Workdate";"Change Workdate")
{
ApplicationArea = All;
}
}
}
}
Create a simple codeunit that subscribe to OnBeforeWordDateChange in My Settings page
codeunit 50110 "Workdate Management"
{
var
UserSetup : Record "User Setup";
[EventSubscriber(ObjectType::Page, Page::"My Settings", 'OnBeforeWorkdateChange', '', true, true)]
local procedure OnBeforeWorDateChange(OldWorkdate: Date; NewWorkDate: Date)
begin
IF not UserSetup.Get(UserId) then
Error('You must enter a valid record for %1 in %2', USERID, UserSetup.TableCaption);
if not UserSetup."Change Workdate" then
Error('You are not allowed to change Wordate.');
end;
}
That is all.
How does it work.
After deploying the extension, search for (ALT+Q) User Setup table and check/uncheck the option "Change Workdate" for the user that may/may not be able to change the workdate
For the users where this value is unchecked, every time they will try to change work date through my settings page, they will receive an error like
This post is provided as is.
Happy coding.