Вы находитесь на странице: 1из 6

I searched a lot, and do a lots of R&D on this.

By this document i want to save your time to write


javascript syntax.

Retrieve context structure data


var LV_DATA = xfa.resolveNode("$record.IM_TEST.FIELDNAME").value;

/*
Where,
LV_DATA : variable to hold data
IM_TEST : context structure variable (Import parameter variable)
FIELDNAME : name of field in structure
*/
Retrieve context internal table data
var LV_DATA = xfa.resolveNode("$record.IM_TEST.DATA[" + INDX + "].FIELDNAME").value;

/*
Where,
INDX : index of table record. (start from zero).
LV_DATA : variable to hold data
IM_TEST : context table variable (Import parameter variable)
FIELDNAME : name of field in internal table
*/
OR if you are looping a table
var IMTEST = xfa.resolveNodes("$record.IM_TEST.DATA[*]");
var LV_DATA;

for (var i = 0; i < IMTEST.length; i++) {


LV_DATA = xfa.resolveNode("$record.IM_TEST.DATA[" + i + "].FIELDNAME").value;
}

/*
Where,
INDX : index of table record. (start from zero).
LV_DATA : variable to hold data
IM_TEST : context table variable (Import parameter variable)
FIELDNAME : name of field in internal table
*/
Retrieve control (field) data
Manipulate (reference) fields in script for adobe forms

Set dynamic Caption


xfa.resolveNode(this.name + ".caption.value.#text").value = "new caption";

/*
Where,
this.name = name of a field. "use on initialize event
*/
Set dynamic reserve space of Caption
this.caption.reserve = "1in";

//use on initialize event


Hide/Visible dynamically any control
this.presence = "hidden"; //values are case sensitive

Caterpillar: Confidential Green


//Options: visible, invisible, hidden, inactive
Get/Set form fields value
this.rawValue = "new value"; //SET

var value = this.rawValue; //GET


Get current index
var INDX = this.index;

var PRNTINDX = this.parent.index; //to get parent container index

var PRNNTINDX = this.parent.parent.index; //to get parent container's parent index


Useful Arithmetic Operators
var y = 5;

x = ++y; //x = 6 and y = 6

x = y++; //x = 5 and y = 6

x = y % 2; //division remainder x = 1
Set floating points of field
this.rawValue = (this.rawValue).toFixed(3);

//Note: 3 is total no. of fraction point to display using ceiling operation


Useful Math functions
this.rawValue = Math.abs(this.rawValue); //to positive value (-1.1 to 1.1)

this.rawValue = Math.ceil(this.rawValue); //to rounded upwards to the nearest


integer (1.1 to 2)

this.rawValue = Math.floor(this.rawValue); //to rounded downwards to the nearest


integer (1.1 to 1)

this.rawValue = Math.round(this.rawValue); //to the nearest integer (1.1 to 1 and 1.5


to 2)
Use Regular Expression
var reg = new RegExp(/[^0-9]/);

if (reg.test("Abcd")){
//expression passed
}
Set focus on filed
xfa.host.setFocus(this);
Populate Alert Message Box
xfa.host.messageBox("Helloo");
Set ToolTip of control
this.assist.toolTip.value = "toolTip text";
Set height of Sub-Form
var b = parseFloat(sfrmName.h) + 5;

Caterpillar: Confidential Green


if (b < 0) {
b = 0;
}
sfrmName.h = b + "mm";

Date and Time format handling


if you are using text field, write use below java script
var curDate = new Date();
var strDate = util.printd("mm/dd/yyyy HH:MM:ss", curDate);

if you are using DateTime adobe field you can directly give pattern to field.
Select DateTime Filed –> Go to property window –> click on Pattern button –> Select accordingly
Note:

mmmm Month Name HH 24 hour time, leading 0

mmm Abbreviated Month Name H 24 hour time

mm Numeric Month, leading 0 hh 12 hour time, leading 0

m Numeric Month h 12 hour time

dddd Day of Week Name MM Minutes, leading 0

ddd Abbreviated Day Name M Minutes

dd Day of Month, leading 0 ss Seconds, leading 0

d Day of Month s Seconds

yyyy Year, 4 digits tt am/pm indication

yy Year, 2 digits t am/pm, single character(a/p)

Play with Uppercase and Lowercase


this.rawValue = this.rawValue.toUpperCase(); "on initialize event convert to
uppercase

this.rawValue = this.rawValue.toLowerCase(); "on initialize event convert to


lowercase

//Using Interactive Scenario (Automatic live case conversion)

Caterpillar: Confidential Green


xfa.event.change = xfa.event.change.toUpperCase(); "on change event convert to
uppercase

xfa.event.change = xfa.event.change.toLowerCase(); "on change event convert to lowe


rcase
Boolean function
var check = Boolean(10 > 9); "returns True
var check = (10 > 9); "returns True
var check = 10 > 9; "returns True
Font customization (control/caption)
this.font.typeface = "Courier"; //font family (font name)
this.font.size = "30pt"; //font size
this.font.weight = "bold"; //font weight (bold | normal)
this.font.posture = "italic"; //font style (italic | normal)
this.fontColor = "0,0,0"; //font color (RR,GG,BB)
this.fillColor = "153,153,153"; //control background color (RR,GG,BB)
this.font.baselineShift = "10px"; //shift font up/down (10/-10)

//for caption you can you below,


this.caption.font.fill.color.value = "255,255,255";

//most other properties are same, ex this.caption.font.*

Cancel Printing
data::prePrint - (JavaScript, client)
xfa.event.cancelAction = 1;
HTML Rich Text Rendering
var envelope = "<?xml version='1.0' encoding='UTF-8'?>" +
"<exData contentType='text/html' xmlns='http://www.xfa.org/schema/xfa-template/2.8/'" +
"><body xmlns='http://www.w3.org/1999/xhtml' xmlns:xfa='http://www.xfa.org/schema/xfa-
data/1.0/' " +
"xfa:APIVersion='Acroform:2.7.0.0' xfa:spec='2.1'>" +
"<p>"+ this.rawValue +"</p></body></exData>";

this.value.exData.loadXML(envelope,1,1);

//Note: use on docClose event and load pdf dynamically.

Loop through all controls (fields) in adobe forms

in this dynamic world, client need all thing dynamic, changes according to the situation. and also
want to reduce all manual efforts.

As our adobe having many types of controls (fields), requirement may come like change this or that
according to this or that value. Here i want to deliver some javascript code and expenations for
looping all fields including master pages and body pages.

Caterpillar: Confidential Green


pageContent() Method
pageContent( INTEGER param1 [, STRING param2 [, BOOLEAN param3 ] ] )
Where,
param1 : page index
param2 : control type (field, draw, subform, area, pageArea, contentArea, empty (default))
param3 : 0 (scan body page), 1 (scan master page)
for detailed information read pageContent() Documentation: Adobe LiveCycle
Designer ES2.

For all intrective controls in Body Page:


Button, Check Box, Date/Time Field, Drop-down List, Signature Field, Image Field, List Box,
Numeric Field, Password Field, Radio Button, and Text Field.
var oNodes = xfa.layout.pageContent(this.layout.page(this)-1, "field", 0);
var oNodesCount = oNodes.length;
for (var i = 0; i < oNodesCount; i++) {
oNodes.item(i).<any property name> = <new value>;
}
For all intrective controls in Body Page:
Circle, Line, Rectangle, Static Image, and Static Text.
var oNodes = xfa.layout.pageContent(this.layout.page(this)-1, "draw", 0);
var oNodesCount = oNodes.length;
for (var i = 0; i < oNodesCount; i++) {
oNodes.item(i).<any property name> = <new value>;
}
For all intrective controls in Master Page:
Button, Check Box, Date/Time Field, Drop-down List, Signature Field, Image Field, List Box,
Numeric Field, Password Field, Radio Button, and Text Field.
var oNodes = xfa.layout.pageContent(this.layout.page(this)-1, "field", 1);
var oNodesCount = oNodes.length;
for (var i = 0; i < oNodesCount; i++) {
oNodes.item(i).<any property name> = <new value>;
}
For all static controls in Master Page:
Circle, Line, Rectangle, Static Image, and Static Text.
var oNodes = xfa.layout.pageContent(this.layout.page(this)-1, "draw", 1);
var oNodesCount = oNodes.length;
for (var i = 0; i < oNodesCount; i++) {
oNodes.item(i).<any property name> = <new value>;
}
Hope this helps.

1. //formCalc
2. $.break.after = "contentArea" ; page break after current subform
3. ; can be processed only for subforms

Caterpillar: Confidential Green


I tried it and it definitely did a page break, although I didn't find it very useful for my particular
situation. The main part of my page was a sub-page/sub-form named "Body." It was contained in a
page that I renamed to Content_Area (I believe it was named "contentArea" when I first created the
form). Here is an example:
Body.break.after = "Content_Area" //page break after content area

I use empty subform (height = 0, no children), place it where I need a conditional break, make it
hidden, set top of next page for this special subform and write a script.
It works like this: when I need a page break, I use script to make the subform visible and only then
the pagebreaks happen.
A workaround, but works just fine.

Caterpillar: Confidential Green

Вам также может понравиться