Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Custom service reply/Wait or Delay in Javascript

Avatar

Level 2

Hi All,

I have a print button that calls a custom print service via Javascript.  Is it possible to get the code to wait for a reply from the custom service before continuing?  Or, is it possible to put a Wait or Delay in the Javascript?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Garreth,

The attached demonstrates the JavaScript equivalent of Num2Time.

FormCalc

// form1.page1.formCalc::initialize - (FormCalc, client)

$.rawValue = Num2Time(Time(), "HHMMSS")

JavaScript

// form1.page1.javaScript::initialize - (JavaScript, client)

var d = new Date();

this.rawValue = myScriptObject.pad(d.getHours()) + myScriptObject.pad(d.getMinutes()) + myScriptObject.pad(d.getSeconds());

Since the time getters return a single integer if value < 10, I created a script object to pad the value with a leading 0 (zero),

// form1.page1.#variables[0].myScriptObject - (JavaScript, client)

function pad(n) {

  return (n < 10 ? '0'+ n : n)

}

Steve

View solution in original post

4 Replies

Avatar

Level 10

The attached form enables a wait time. It uses 2 hidden fields, one to capture the time the button is clicked and a second to calculate the current time. The script on the button click event is as follows:

// form1.subform1.btn::click - (JavaScript, client)

form1.subform1.timeAtClick.execEvent("calculate");

var endTime = parseInt(form1.subform1.timeAtClick.rawValue) + parseInt(form1.subform1.waitTime.rawValue);

var currentTime = 0;

while (currentTime < endTime) {

     form1.subform1.currentTime.execEvent("calculate");

     currentTime = parseInt(form1.subform1.currentTime.rawValue);

}

xfa.host.messageBox("Done waiting " + form1.subform1.waitTime.rawValue + " seconds.","Timer",3,0);

Steve

Avatar

Level 2

Hi Steve,

Many thanks for your reply.

Since I am using a form guide I cannot use the FormCalc behind timeAtClick and currentTime.  Do you know how to code Num2Time(Time(), "HHMMSS")
in JavaScript?

Garreth

Avatar

Correct answer by
Level 10

Hi Garreth,

The attached demonstrates the JavaScript equivalent of Num2Time.

FormCalc

// form1.page1.formCalc::initialize - (FormCalc, client)

$.rawValue = Num2Time(Time(), "HHMMSS")

JavaScript

// form1.page1.javaScript::initialize - (JavaScript, client)

var d = new Date();

this.rawValue = myScriptObject.pad(d.getHours()) + myScriptObject.pad(d.getMinutes()) + myScriptObject.pad(d.getSeconds());

Since the time getters return a single integer if value < 10, I created a script object to pad the value with a leading 0 (zero),

// form1.page1.#variables[0].myScriptObject - (JavaScript, client)

function pad(n) {

  return (n < 10 ? '0'+ n : n)

}

Steve

Avatar

Level 2

Hi Steve,

Thank you for your help.  It work a charm.

Garreth