Hello,
I am facing problems in NAV 2018 with the Task Scheduler that runs Job Queues.
When a new NAV session is opened, all Job Queues are rescheduled by the codeunit Job Queue User Handler (function RescheduleJobQueueEntriesOnCompanyOpen).
My troubles come from the fact that these tasks will be executed on behalf of the current User ID.
So, a Job Queue will always run with the permission of the last logged in user instead of the User ID on the Job Queue Entry.
Have you already faced this problem? Is there a workaround?
Thank you in advance for your help.
0
Answers
When a Job Queue Entry is Inserted/Rescheduled etc, we added an IF condition to ensure the field "User ID" is only overwritten with "USERID" if it is currently empty.
We also had to customise the code in COD453 - "EnqueueJobQueueEntry"
so after the Task has been scheduled, we modify the user set on the Scheduled Task, to the User ID of the Job Queue Entry.
TASKSCHEDULER.CREATETASK does not have a parameter for User ID, so we had to resort to renaming it after the Scheduled Task had been created.
In your version they may have added an event "OnAfterJobQueueScheduleTask" which you could subscribe to, in order to make this change. Which is how we would have done it, but the event doesn't exist in our version.
The extremely annoying thing is that when a new NAV session is opened, all Job Queues are rescheduled by the codeunit Job Queue User Handler (function RescheduleJobQueueEntriesOnCompanyOpen).
Even though I have tried to modify the code in COD453 the scheduled task is still created in the user name for the user who logs on to the company next time.
So, could be nice to get a hint about the code change you've made.
At our customer with NAV 2017 CU 18, we had C/AL code, which changed user ID after Scheduled Task has been created.
Now we merged CU 29 and our code, which changed user ID stopped working. Modification of system Table Scheduled Task has now some internal validation, which prevents to changing user ID:
"The task cannot be run because the user account that is assigned to run the task has been altered. The task has been canceled."
Customer does not want to run scheduled tasks under ID of user, who enabled scheduled task, they want to run tasks under another user ID.
Please, can anyone help me? Thanks!
I am joining with the same question; we are facing the same issue on the BC130 on-prem CU08 platform.
I do this in 2017, and works fine.
Actually, there is not a problem with the "User ID" in the Job Queue Entry, but with the "User ID" in the Scheduled Task. Anything I do, I am not able to change it, therefore all the background sessions started by the scheduler run in the context of the user, who created the Job Queue Entry record. So, e.g. all the User Id's, everywhere in the system, are filled by the wrong user name and so on...
```
[EventSubscriber(ObjectType::Table, Database::"Scheduled Task", 'OnBeforeInsertEvent', '', false, false)]
local procedure ScheduledTaskOnBeforeInsert(var Rec: Record "Scheduled Task")
var
User: Record User;
JobQueueEntry: Record "Job Queue Entry";
JobQueueRecRef: RecordRef;
FldRef: FieldRef;
begin
if Rec."Run Codeunit" <> 448 then exit;
JobQueueRecRef := Rec.Record.GetRecord();
if not JobQueueRecRef.Find() then exit;
if JobQueueRecRef.Number() <> Database::"Job Queue Entry" then exit;
FldRef := JobQueueRecRef.Field(2);
User.SetRange("User Name", FldRef.Value());
if not User.FindFirst() then exit;
if Rec."User ID" = User."User Security ID" then exit;
Rec."User ID" := User."User Security ID";
Rec."User Name" := User."User Name";
end;
```
I have tried it right now, but it doesn't work for me. Even when I change the user in Scheduled Task OnBeforeInsert, it shouts the error :-(
I am not sure if it can have an impact on the result, but I am writing the code in the "good old" C/AL...
Actually, I don't know whether it is possible to find it anywhere. I discussed it with an MS support specialist and he advised me that this server property exists and I can change it...
I just had this issue on 2017 CU30 and added the key manually to the CustomSettings.config file for the NST, restarted and it solved the problem
Thank you very much
Server administration module will tell you that "The configuration setting 'EnableUserConsistencyValidationOnTasks' is not valid for Microsoft Dynamics NAV Server."