Global Scripts and IP filters

Quick question. In another post, I was trying to popup a report, populate the report and PRINT the report using a Global Script Timer. That works fine, but I have a question about REFINING it.

Can I RELIABLY print from only one client running out of say 5 total by specifying an ip address in an IF statement??

I have tried it and it SEEMS to work… just not sure why it wasn’t mentioned before and why I was told that I couldn’t LIMIT the script to only ONE client. Is there something I need to know about that would cause problems??

# Get a list of the alarms that have not yet been printed

alarms = fpmi.db.runQuery("SELECT L.AlarmLog_ndx, LEFT(point_path,3) AS line, (SELECT f.ftsheet FROM ftsheet_reference f WHERE f.line=LEFT(L.point_path, 3) AND f.item_name = L.item_name LIMIT 1) as ftsheet, L.item_name, L.state_name, L.active_time, (SELECT R.recipe FROM recipe R WHERE R.line_id=LEFT(L.point_path, 3) AND R.t_stamp< L.active_time ORDER BY R.t_stamp DESC LIMIT 1) as Recipe, (SELECT B.batch_number FROM batches B WHERE B.line_id=LEFT(L.point_path, 3) AND B.t_stamp < L.active_time ORDER BY B.t_stamp DESC LIMIT 1) as Batch FROM alarmlog L WHERE L.printed = 0 AND L.severity = 1 LIMIT 1")

ip = fpmi.net.getIpAddress()

if ip == "10.24.14.112" and len(alarms)>0:
   alarm = alarms[0]
   id = alarm["AlarmLog_ndx"]
   name = alarm["state_name"] 
   itemname = alarm["item_name"]
   activetime = alarm["active_time"]
   ftsheet = alarm["ftsheet"]
   line = alarm["line"]
   recipe = alarm["Recipe"]
   batch = alarm["Batch"]
   window = "Report"
   fpmi.nav.openWindow("Report", {"Alarm" : name, "item_name" : itemname, "ftSheet" : ftsheet, "active_time" : activetime, "line" : line, "recipe" : recipe, "batch" : batch})
   def openAndPrint(Report=window):
      import fpmi
      # pass alarm name in as parameter to report window
      def printLater(Report=Report):
         import fpmi
         window = fpmi.gui.getWindow(Report)
         report = window.getRootContainer().getComponent('Report Viewer')
         report.print(None, 0)
      fpmi.system.invokeLater(printLater, 9000)
   fpmi.system.invokeLater(openAndPrint)
   def closeAfterPrint(Report=window):
      import fpmi
      fpmi.nav.closeWindow(Report)
   fpmi.system.invokeLater(closeAfterPrint, 11000)
   fpmi.db.runPrepStmt("UPDATE alarmlog SET printed=1 WHERE alarmlog_ndx = ?", [id])

With the understanding that the IP address would have to be static, is this a sound IDEA??

Sure its a sound idea, you could also use the hostname if the IP wasn’t static.

This is a perfectly good thing to do, I think the argument you heard before was a somewhat academic point: FactoryPMI can’t guarantee that there is 1 and exactly 1 client running on that machine. There could be two, there could be zero, etc. It is up to you to ensure that there is 1 client running on that computer.

Ok, so with using the hostname, I am issured that it will only print on that machine. As far as OTHER clients running on that machine, i’m not too concerned about that.

Thanks Carl

Quick question concerning this code:

def openAndPrint(Report=window):
      import fpmi
      # pass alarm name in as parameter to report window
      def printLater(Report=Report):
         import fpmi
         window = fpmi.gui.getWindow(Report)
         report = window.getRootContainer().getComponent('Report Viewer')
         report.print(None, 0)
      fpmi.system.invokeLater(printLater, 9000)

I still want to use the invokeLater, but I would also like to make sure that the “Report” window is open before I Print it.

I know that the “Report” window is the ACTIVE window when it opens, so is there ANY way to use app.nav.getCurrentWindow()
from within a Global Script Timer?

sure you just need to do an “import app” first

I’m trying to create another Global script for STARTUP.

Example: A user logs in. Then I want to run a query to see if this account is secure. If not, I want to open a window. If it is secure, do nothing.

Here is what I have so far

username = fpmi.security.getUsername()
SQquery = fpmi.db.runScalarQuery("SELECT Secure FROM users WHERE username='%s' LIMIT 1"%username)

if len(SQquery)>0:
   data = SQquery[0]
   z = SQquery["Secure"]
   if z !=1:
      fpmi.nav.openWindow("SecurityQuestion")

I get this error:

Any Ideas?

Sure, look at line 3 of the error message:
TypeError: len() of unsized object

fpmi.db.runScalarQuery returns a single value - not a dataset.