Does the routine you use have permissions? You can set this as a property of the object. Example here for a codeunit: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-permissions-property
same applies to a number of other objects as the resource states