Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Javascript function not working in LiveCycle

Avatar

Level 1

I've just completed importing an existing acrobat form into LiveCycle for editing.  During the import process, I received this LiveCycle warning:

The form includes a simple JavaScript Function that looks really good, but probably doesn't reference the correct objects in the form. Here's the Code:

topmostSubform.Page1.Text1::calculate - (JavaScript, client)
(function() {

var v1 = Number(this.getField ("MinutesRow1").value);
var v2 = Number(this.getField ("MinutesRow2").value);
var v3 = Number(this.getField ("MinutesRow3").value);
var v4 = Number(this.getField ("MinutesRow4").value);
var v5 = Number(this.getField ("MinutesRow5").value);
var v6 = Number(this.getField ("MinutesRow6").value);
var v7 = Number(this.getField ("MinutesRow7").value);
var v8 = Number(this.getField ("MinutesRow8").value);
var v9 = Number(this.getField ("MinutesRow9").value);
var v10 = Number(this.getField ("MinutesRow10").value);
var v11 = Number(this.getField ("MinutesRow11").value);
var v12 = Number(this.getField ("MinutesRow12").value);
var v13 = Number(this.getField ("MinutesRow13").value);
var v14 = Number(this.getField ("MinutesRow14").value);
var v15 = Number(this.getField ("MinutesRow15").value);

    //perform the calculation
    var result = (v1+v2+v3+v4+v5+v6+v7+v8+v9+v10+v11+v12+v13+v14+v15)/60;

    //set the value of this field to the result
    event.value = result;
})();

The object references seem to be correct, and the code seems solid. Does anyone have any ideas?

 

2 Replies

Avatar

Level 1

Here's the image that didn't appear in my post above:

Warning.png

Avatar

Level 10

Hi.

AcroForms (forms created in Acrobat) use a version of JavaScript that is close to Code JavaScript. So syntax like this.getField are specific to AcroForms.

XFA Forms (forms created in LiveCycle Designer) are completely different. The version of JavaScript has subtle but important differences.

For example, "this" in AcroForms means the document, whereas in XFA Forms, "this" refers to the object that contains the script.

Have a look here at an example that explains how to reference objects in LC Designer: http://assure.ly/kUP02y.

So for example:

function myFunction () {

var v1 = MinutesRow1.rawValue;

// the rest of the variables

var myResult = (v1+v2+v3+v4+v5+v6+v7+v8+v9+v10+v11+v12+v13+v14+v15)/60;

return myResult;

}

Good luck,

Niall