2 Replies Latest reply on Feb 6, 2011 8:27 PM by Jo_2005

    Delay a Script with Set Time Out

    Jo_2005 Level 1

      Hello,

       

      I have a script that calculates when a duration time field is equal to a count time field an alert will show.

       

      The script works and the alert shows except that the alert is showing twice.

       

      I have tried to delay the alert from showing to slow down the script to solve the problem of the alert showing twice.

       

      To delay the script the setTimeOut function has been used.

       

      There is an console error to say that the test function is not defined.

       

      Can any one please provide assistance in setting up the set time out function correctly?

       

      function AlertAction()

      {

      //  alert when times are matched

       

      // get the string value for the agenda item duration

       

      var sAgendaTime = this.getField("Action Time").value;

      // only perform if there is a value for the event

      if(sAgendaTime != '') {

      // convert agenda item duration into an array with the elements for minutes and seconds with the adjusted time

      var aAgendaTime = sAgendaTime.split(":");

      var sAgendaWarning = util.printf("%02d:%02d:%02d", 0, aAgendaTime[0] - 0, aAgendaTime[1]);

      // compare to the stop watch display value

      var t = this.getField("StopWatchDisp");

      if(t.value.substr(0,8) == sAgendaWarning)

       

      // set time out used to delay the alert from showing

       

      run = app.setTimeOut("test()",3000);

       

      function test()

      {

      // A MouseUp action

      var nButton = app.alert({

      cMsg: "WARNING - Time has now run out for this Agenda Item!!",

      cTitle: "Action Focus Agenda Time Has Run Out",

      nIcon: 1, nType: 0

      });

       

      }

      }

       

      }

      }

      app.clearTimeOut(run);

       

      Any assistance will be most appreciated, I need to solve this problem to give the form to the end users.

       

      Many thanks!

        • 1. Re: Delay a Script with Set Time Out
          try67 MVP & Adobe Community Professional

          You need to define the function before the line that calls app.setTimeOut on it.

          Also, I would recommend using another name for your function, as test is very generic and is already used by the String object, for example.

          1 person found this helpful
          • 2. Re: Delay a Script with Set Time Out
            Jo_2005 Level 1

            Thank you for your advice.

             

            I have taken the setTimeOut statement out of the document level script AlertAction.

             

            In the calculation event of a text field  I have called the AlertAction function within the  set time out statement and this has fixed the error with the alert message, which is now showing once instead of twice.

             

            app.setTimeOut("AlertAction()",3000);