I'm trying to print labels to a Zebra printer connected to a laptop running a Perspective session. I want to view the connected printers and the default printer on that laptop. When my script runs, it returns null. There are no printers configured on this gateway. If I run the script in the script console, it returns the printer(s) from my computer.
Shouldn't this function return printers from the local machine running the session, not the gateway? Am I missing something obvious?
"Local" to whatever execution scope is running the script. If you call it from the gateway (via tag event script, SFC, alarm pipeline, scheduled report, or Perspective session) - it's going to give you whatever the OS reports as the default printer name to the Gateway. If you're executing your code in the client or designer (in the script console or a Vision window), it's going to give you whatever the OS reports as the default printer name to that local executable; Vision/the Designer have tigher integration with the local system than is possible with Perspective.
So, we added a network printer to the gateway (set as default), and we get either an empty list from system.print.getPrinterNames(), or we get null back from system.print.getDefaultPrinterName(). There is also the standard "Microsoft XPS Document Writer" driver installed on the gateway. I would expect that to show up in the list of printer names as well.
Is there any further advice you can provide to assist troubleshooting this considering these changes?
Windows printer name lists and default printer status is per-user. The gateway runs as a service in the background, typically under a system account that doesn't have most network privileges. Logging into the server's desktop as a regular user and adjusting pretty much any settings has no effect on the service.
You should get your IT group to provide a suitably-configured user account for the background service.