hi,
this scenario is not possible (with automations), because this function needs a server and a client. running the function using the rtc client, there is a client. running it as nas job then there is no client, but server with server! so change the code:
- use simple nav functions
- OR try using dotnet functions
check also https://community.dynamics.com/nav/f/34/p/115355/236313.aspx
best regards