Hi,
at first:
I'm new in the forum, so I apologize for eventually posting my topic in the wrong forum section. Also I apologize for any grammar mistakes as I am not a native speaker.
I'd like to only let permitted Users change the work date. I found several topics in the forum about this but unfortunately there was no solutionn for me.
According to my supervisor I must not use any timer-based solutions.
What are my options? There doesn't seem to be any specific trigger being executed after changing the work date...
I tried out several triggers in Codeunit 1 (OnDatabaseModify/OnDatabaseDelete/... , MakeDateText/MakeTimeText/...) but it didn't have any effect.
This is my code I want to run (it's in a separate Codeunit):
WorkDatePermissionCheck()
IF NOT UserHasPermission THEN BEGIN
IF WORKDATE <> TODAY THEN BEGIN
WORKDATE := TODAY;
MESSAGE(Error001,USERID); // ERROR(Error001,USERID);
END;
END;
UserHasPermission() : Boolean
IF NOT UserSetup.GET(USERID) THEN
EXIT(FALSE);
EXIT(UserSetup."Allow Changing Workdate");
Thanks in advance
Wittgenstein
Answers
at first: your English is fine!
Because you don't mention a reason why the WORKDATE may not be changed I assume it just is a 'security' measure requested by someone who doesn't understand NAV.
The only way (I know of) to do something remotely close to this is to :
a- find every place in NAV where WORKDATE is used and call your function there...
b- dynamically change user allowed posting range every day/login.
But you understand that this is not the way any erp system should be setup.
thanks for your reply.
Obviously. It's a customer request.
a- This would probably take tons of changes in standard objects. I don't know if our customer would be happy with that. Nevertheless I will give it a try. OMA should help there.
b- So you mean to modify the "Allow Posting From" and the "Allow Posting To" Fields in User Setup on startup? Hm. That wouldn't even require to touch standard objects in NAV 2016...
Anyway. I have to clarify if our customer needs the work date user permission only for posting routines or also for other routines accessing the work date.
Maybe I can convince our customer to just sensitize their Users to not touching the work date.
However thanks for your answer. Let me know if you have more ideas. I'll let you know if I have found a solution for myself
Edit
My feedback:
The only reliable option to suppress workdate change directly was a solution with a timer. It's not very elegant IMHO but it works.
Anyways I decided to go with Peter+is1's suggestion 'b'. Thanks again for your help, Peter!
As a side information: The workdate change is controlled in the executables of Dynamics NAV. So there is no way to manipulate and/or customioze this option directly.
I have another idea for a solution but I don't know if it would work.
Can you somehow have access to the user32.dll or any other WinDlls (WinAPI)? Maybe with an Automation variable or a DotNet variable? Or do I have to write my own Dll in C# for accessing these functions?
With FindWindow/FindWindowEx you can maybe get the window handle and manipulate it.
As I said, I don't know if it works or if it is a silly idea but imo it's worth a try...
I already managed to Hide and Disable the OK-Button in an external process. But I don't know how to use WinAPI functions out of NAV. Is this possible or do I have to create a "third-party" Dll?