Facility Control

 View Only
  • 1.  Reference another task on a different button

    Posted 02-17-2017 19:44
    Hi,
    I was wondering if there was a quick way to reference a task that is assigned to a different button in a new button so I wouldn't have to keep repeating code. Is this possible?


  • 2.  RE: Reference another task on a different button

    Posted 02-21-2017 14:11

    There are 2 ways to do this:
    1. Take your script that you want to run in multiple places and make it a function. You can put that function in an block at the top of your panel and run it from anywhere. The cool thing with this approach is you can add arguments to your function for more flexibility.

    <abs contexttype="opengear" style="">
       <meta>
          <api>function myFunction(name)
    {
       ogscript.debug("Hello " + name);
    }
    </api>
       </meta>
       <button buttontype="push" height="152" left="20" name="Hello James" top="25" width="224">
          <task tasktype="ogscript">myFunction('James');
    </task>
       </button>
       <button buttontype="push" height="152" left="258" name="Hello Bill" top="26" width="224">
          <task tasktype="ogscript">myFunction('Bill');</task>
       </button>
    </abs>

    2 You can put a trigger ID on a button and use ogscript.fireGPI to trigger it. This can also be done to trigger buttons in 2 different panels:

    <abs contexttype="opengear" style="">
       <button buttontype="push" gpi="HelloButton" height="152" left="20" name="Hello World" top="25" width="224">
          <task tasktype="ogscript">ogscript.debug('Hello World');</task>
       </button>
       <button buttontype="push" height="152" left="258" name="Trigger Button" top="26" width="224">
          <task tasktype="ogscript">ogscript.fireGPI('HelloButton', null, false); //global = true/false to notify all of DashBoard or just this panel</task>
       </button>
    </abs>

    #DashBoard