Job Queue with Task Scheduler and User ID

nicolassaleron
Member Posts: 11
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.
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
Best Answer
-
Hi, we faced the same issue after upgrading to 2017 some time ago. I am not sure about your version, but in ours there were not sufficient events to subscribe to so we ended up having to modify the MS code.
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.
6
Answers
-
Hi, we faced the same issue after upgrading to 2017 some time ago. I am not sure about your version, but in ours there were not sufficient events to subscribe to so we ended up having to modify the MS code.
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.
6 -
Thank you, I will implement the trick0
-
I still have a problem with this in NAV 2018 CU6. Could be nice to see some of tyhe actual code changes you guys have made.
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.0 -
Hi, I am struggling with Task Scheduler.
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!Martin Bokůvka, AxiomProvis1 -
Bump, anyone knows? PleaseMartin Bokůvka, AxiomProvis1
-
Doomhammer wrote: »Bump, anyone knows? Please
I am joining with the same question; we are facing the same issue on the BC130 on-prem CU08 platform.0 -
Just subscribe to table "Job Queue Entry" OnAfterModify event, and set the userid.
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...0 -
Mariocv you are on the right track. Subscribe to the scheduled task and then make your changes there.
```
[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;
```0 -
did anyone succeed in resolving '"The task cannot be run because the user account that is assigned to run the task has been altered. The task has been canceled." error?. If yes, please let me know how it is done.0
-
Mariocv you are on the right track. Subscribe to the scheduled task and then make your changes there.
```
[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...0 -
A solution of my problem found (thanks to MS support guys): Server configuration now has a setting key EnableUserConsistencyValidationOnTasks, which is currently set to True by default. If it is set to False, it is possible to change the user in the Scheduled Task table. Works perfectly for the BC13 CU08 (I did not test it in NAV2017, I will be glad if someone will and tell me results).0
-
Hi Mariocv, Where can I finde this fix? Is it in customersource or partnersouce?
0 -
-
A solution of my problem found (thanks to MS support guys): Server configuration now has a setting key EnableUserConsistencyValidationOnTasks, which is currently set to True by default. If it is set to False, it is possible to change the user in the Scheduled Task table. Works perfectly for the BC13 CU08 (I did not test it in NAV2017, I will be glad if someone will and tell me results).
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 problem0 -
I just applied the modification on Nav 2018 CU27 and now it works perfectly!
Thank you very much0 -
Does not work on 2017 CU 6.
Server administration module will tell you that "The configuration setting 'EnableUserConsistencyValidationOnTasks' is not valid for Microsoft Dynamics NAV Server."Don't just take my word for it, test it yourself0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions