Options

Using StartSession

rickyl76rickyl76 Member Posts: 25
Is it possible to capture an error that may have been generated by using StartSession? In my example i want to raise a sales order in another company based on a trigger. If, say the customer was blocked in the company that startsession was used, is there a way i can get the last error and save it somewhere? By using a return value on Startsession it just seems to indicate that the startsession was successful. In my instance the startsession was successful but what it tried to do wasn't.

Answers

  • Options
    Wisa123Wisa123 Member Posts: 308
    The startsession just indicates that the new Background session was started successfully. Since the newly created session runs asynchronously errors in the background session cannot be retrieved using the return value.

    Therefore you must log the Error in the context of the background session. Instead of
    StartSession(CreateSalesOrderCodeunit,...)
    

    you could try
    StartSession(CodeunitRunner,....)
    

    where CodeunitRunner is it's own Codeunit doing nothing but
    if not CreateSalesOrderCodeunit.Run() then
        SomeLogFunction(GetLastError());
    

    Austrian NAV/BC Dev
Sign In or Register to comment.