AL icon indicating copy to clipboard operation
AL copied to clipboard

EnqueueBackgroundTask error when using function on page or pageextension

Open mynavblog opened this issue 7 years ago • 3 comments

Describe the bug I have an error when trying function CurrPage.EnqueueBackgroundTask error when using it on page or pageextension. The web client crashes.

the whole error is inserted at the bottom of the issue.

To Reproduce Steps and to reproduce the behavior:

  1. Create a page
  2. Run Action described below

AL Code to reproduce the issue I created the action which should start the background task (tried also to add it onOpenPage trigger)

action("Task") { Caption = 'Task'; Promoted = true; PromotedCategory = New; ApplicationArea = All; trigger OnAction() var MyDictionary: Dictionary of [Text, Text]; begin MyDictionary.Add('Param1', 'Value1'); MyTaskId := 1; CurrPage.EnqueueBackgroundTask(MyTaskId, Codeunit::MyCodeunit2); end; }

trigger OnPageBackgroundTaskCompleted(TaskId: Integer; Results: Dictionary of [Text, Text])
var
begin
    Message('ok for task: %1', TaskId);
end;

trigger OnPageBackgroundTaskError(TaskId: Integer; ErrorCode: Text; ErrorText: Text; ErrorCallStack: Text)
var
    myInt: Integer;
begin
    Message('not ok for task: %1', TaskId);
end;

and I have also the Codeunit which should be run. (I do not know if there is any special requirements for the Codeunit as cannot find in the documentation)

codeunit 50100 MyCodeunit2 {

trigger OnRun()
begin
    myInt := 1;
    MyDictionary := Page.GetBackgroundParameters();
    MyResult.Add('xxx', 'ttt');
    Page.SetBackgroundTaskResult(MyResult);

end;

}

Expected behavior As I understand it should run the backround task on the page.

Versions:

  • AL Language: 3.0.126610
  • Business Central: Platform 14.0.32600.0 + Application 32615 (DK Dynamics NAV 14.1) Docker Image: mcr.microsoft.com/businesscentral/onprem:dk

Error from docker log: TimeGenerated : 17-06-2019 12:37:10 EntryType : Error Message : Server instance: NAV Tenant ID: default Session type: WebClient Session ID: 399 User: BCDK\mynavblog Type: System.NotImplementedException Message: The method or operation is not implemented. StackTrace: at Microsoft.Dynamics.Nav.Runtime.NavApplication Method.InvokeMethod(ITreeObject obj, String methodName, Object[ ] args, Boolean resolveHandler, Boolean throwOnNotFound) Source: Microsoft.Dynamics.Nav.Ncl HResult: -2147467263 StackTrace: at Microsoft.Dynamics.Nav.Runtime.NavApplication Method.InvokeMethod(ITreeObject obj, String methodName, Object[ ] args, Boolean resolveHandler, Boolean throwOnNotFound) ---------------------------------- Type: System.Reflection.TargetInvocationException Message: Exception has been thrown by the target of an invocati on. StackTrace: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInterna l(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, Cu ltureInfo culture) at Microsoft.Dynamics.Nav.Runtime.NavApplicationMethod.Inv okeMethod(ITreeObject obj, String methodName, Object[] args, Bo olean resolveHandler, Boolean throwOnNotFound) Source: mscorlib HResult: -2146232828 StackTrace: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInterna l(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, Cu ltureInfo culture) at Microsoft.Dynamics.Nav.Runtime.NavApplicationMethod.Inv okeMethod(ITreeObject obj, String methodName, Object[] args, Bo olean resolveHandler, Boolean throwOnNotFound) ---------------------------------- Type: System.NotImplementedException Message: The method or operation is not implemented. StackTrace: at Microsoft.Dynamics.Nav.Runtime.NavChildSessionTaskSched uler.ScheduleChildSessionTaskRun(NavChildSessionTaskRuntime tas kRuntime) at Microsoft.Dynamics.Nav.Runtime.NavForm.EnqueueBackgroun dTask(DataError errorLevel, ByRef1 taskId, Int32 objectId, ByR ef1 parameters, Boolean cancelOnRecordChange, Int32 timeout) at Microsoft.Dynamics.Nav.BusinessApplication.PageExtensio n50100.Task_a45_OnAction_Scope.OnRun() at Microsoft.Dynamics.Nav.Runtime.NavMethodScope.Run() at Microsoft.Dynamics.Nav.BusinessApplication.PageExtensio n50100.Task_a45_OnAction() Source: Microsoft.Dynamics.Nav.Ncl HResult: -2147467263 StackTrace: at Microsoft.Dynamics.Nav.Runtime.NavChildSessionTaskSched uler.ScheduleChildSessionTaskRun(NavChildSessionTaskRuntime tas kRuntime) at Microsoft.Dynamics.Nav.Runtime.NavForm.EnqueueBackgroun dTask(DataError errorLevel, ByRef1 taskId, Int32 objectId, ByR ef1 parameters, Boolean cancelOnRecordChange, Int32 timeout) at Microsoft.Dynamics.Nav.BusinessApplication.PageExtensio n50100.Task_a45_OnAction_Scope.OnRun() at Microsoft.Dynamics.Nav.Runtime.NavMethodScope.Run() at Microsoft.Dynamics.Nav.BusinessApplication.PageExtensio n50100.Task_a45_OnAction()

mynavblog avatar Jun 17 '19 10:06 mynavblog

@mynavblog that particular API was experimental in the Spring release but we missed marking it as such. You should try this code on the latest preview release: https://freddysblog.com/2019/07/31/preview-of-dynamics-365-business-central-2019-release-wave-2/ Let us know if you encounter any issues.

atoader avatar Aug 09 '19 09:08 atoader

@atoader - hi, I checked that one on internal build from today. And the good info it is not crashing Business Central. Bad is that sit not works for me. Maybe I cannot use it but when I try to debug it it goes one, two line in the Codeunit and then it is not continue the code.

mynavblog avatar Sep 10 '19 14:09 mynavblog

Page Background Task is only working on Wave 2 2019 release of Business Central (15).

However, as the document specify, the debugger as a couple of limitation to be aware of: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-page-background-tasks

" Like with other code in the application, you debug page background tasks by using the integrated debugger (see Debugging). However, there are a couple limitations to be aware of:

  • Only one session can be debugged at a time.
  • If a breakpoint in a child session is hit, the child session will become the debugged session.
  • Other sessions will continue to run normally.
  • In other sessions, the breakpoints and error sessions will be ignored until the child session is completed. "

This means that probably in your case, the completion trigger run before the child session released the debugger, and therefor the breakpoint was missed.

dagirard avatar Oct 21 '19 09:10 dagirard