[go: up one dir, main page]

0% found this document useful (0 votes)
31 views12 pages

Javascript Code Templates

This document provides a comprehensive list of JavaScript code templates specifically designed for use in Adobe forms. It includes various functionalities such as adding currency symbols, calculating subtotals, setting dynamic captions, and handling date formats, among others. Additionally, it highlights differences between JavaScript and FormCalc syntax and offers useful links for further learning.

Uploaded by

tahadiricannn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views12 pages

Javascript Code Templates

This document provides a comprehensive list of JavaScript code templates specifically designed for use in Adobe forms. It includes various functionalities such as adding currency symbols, calculating subtotals, setting dynamic captions, and handling date formats, among others. Additionally, it highlights differences between JavaScript and FormCalc syntax and offers useful links for further learning.

Uploaded by

tahadiricannn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

JAVASCRIPT CODE TEMPLATES

Umutcan Alver // 11.12.2019

1- Adding Currency Symbol


var A = DATA.index;
var waerk = xfa.resolveNode("data.Page.GT_ITEM.DATA["+A+"].WAERK");

switch (waerk)
{
case "EUR" :
this.locale = "de_DE";
break;
case "TRY" :
this.locale = "tr_TR";
break;
case "USD" :
this.locale = "en_US";
break;
}

2- Calculating sub total for every page


var fields;
var total = 0;
var page = xfa.layout.page(this);

for(var j = 0 ; j < page-1; j++)


{
fields = xfa.layout.pageContent(j, "field", 0);
for (var i=0; i < fields.length; i++)
{
if (fields.item(i).name == "KWERT") >> Toplamı alınacak alan.
{
total = total + fields.item(i).rawValue;
}
}
}
this.rawValue = total;

3- Set Floating Points Of Field


this.rawValue = (this.rawValue).toFixed(3);

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


4- Set Focus On Field
xfa.host.setFocus(this);

5- Populate Alert Message Box


Xfa.host.messageBox(“Hello”);
6- Set Height Of Sub-Form

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

7- 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
*/

8- Retrieve Context Itab 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
*/

9- Set Dynamic Caption


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

/*
Where,
this.name = name of a field. "use on initialize event
*/
10- Set Dynamic Reserve Space Of Caption

this.caption.reserve = "1in";
//use on initialize event
11- Hide/Visible Dynamically Any Control

this.presence = "hidden"; //values are case sensitive

//Options: visible, invisible, hidden, inactive

Example:
If ( this.rawValue == “TRY” )
{
data.pageSet.Page1.Subform2.presence = “hidden”;
}

12- Get/Set Form Fields Value


this.rawValue = "new value"; //SET
var value = this.rawValue; //GET

13- 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

14- 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

15- 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)

16- Use Regular Expressions

var reg = new RegExp(/[^0-9]/);

if (reg.test("Abcd")){
//expression passed
}

17- Set Tooltip Of Control

this.assist.toolTip.value = "toolTip text";

18- Date And Time Format Handling

var curDate = new Date();


var strDate = util.printd("mm/dd/yyyy HH:MM:ss", curDate);

19- 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)

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 lowercase

20- Boolean Function

var check = Boolean(10 > 9); "returns True


var check = (10 > 9); "returns True
var check = 10 > 9; "returns True
21- Font Customization

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,


If ( this.rawValue > 100 )
{
this.caption.font.fill.color.value = "255,255,255";
}
//most other properties are same, ex this.caption.font.*

22- Cancel Printing

data::prePrint - (JavaScript, client)


xfa.event.cancelAction = 1;

23- HTML Richtext 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.


24- 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
*/

25- Loop through all controls (fields) in adobe forms


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)

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>;

}
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>;

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>;

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>;

26- Dynamic Font Setting

data::ready:layout - (JavaScript, client)


var totalPages = xfa.layout.pageCount();
var i = 0;

for (i = 0; i < totalPages; i++) {


setFont("field", 0);
setFont("draw", 0);
setFont("field", 1);
setFont("draw", 1);
}

function setFont(type, page) {


var oField = xfa.layout.pageContent(i, type, page);
var n = oField.length;
var j = 0;

for (j = 0; j < n; j++) {


oField.item(j).font.typeface = "Courier"; //any valid font name
}
}

27- Reduce Font Size Of A Label


if( this.rawValue == "CompCode" ) { this.font.size ="30pt"; }

28- Interactive Forms Events

data.#subform[0].#subform[1].#subform[3].Table2.Row5.TOPLAMKDV::calculate - (JavaScript,
client)

var total = 0;
total = Row4.KDVTUTAR.rawValue + Row2.ISKONTOLUTOPLAM.rawValue;
this.rawValue = total;
data.#subform[0].#subform[1].#subform[3].Table2.Row4.KDVTUTAR::calculate - (JavaScript, client)
var total = 0;
total = Row2.ISKONTOLUTOPLAM.rawValue * 18 / 100 ;
this.rawValue = total;

data.#subform[0].#subform[1].#subform[3].Table2.Row3.ISKONTOTOPLAM::calculate - (JavaScript,
client)

var fields = xfa.layout.pageContent(xfa.layout.page(this)-1, "field", 0);


var total = 0;
for (var i=0; i <= fields.length-1; i++) {
if (fields.item(i).name == "ISKONTO") {
total = total + fields.item(i).rawValue;
}
}
this.rawValue = total;
data.#subform[0].#subform[1].IT_ITEM.DATA.ISKONTO_ORAN::exit - (JavaScript, client)

if ((this.resolveNode("$").rawValue != null && this.resolveNode("$").rawValue != ""))


{
this.resolveNode("ISKONTO").rawValue = ( this.resolveNode("BIRIM_FIYAT").rawValue *
this.resolveNode("ISKONTO_ORAN").rawValue / 100 ) * this.resolveNode("MENGE").rawValue;
this.resolveNode("TOPLAM").rawValue = this.resolveNode("MENGE").rawValue *
this.resolveNode("BIRIM_FIYAT").rawValue;
}

29- Some Differences Between Javascript and FormCalc


FormCalc Syntax
if (i >= 10) then
i = i + 10
endif
or

if (i >= 10) then


i = i + 10
elseif (i >= 5) then
i = i + 5
i = i * 2
else
i = i + 1
endif

JavaScript Syntax
if (i >= 10)
i = i + 10;
or

if (i >= 10)
i = i + 10;
else if (i >= 5)
{
i = i + 5;
i = i * 2;
}
else
i = i + 1;

FormCalc Syntax
for i = 1 upto 10 do
MyList.addItem(i)
endfor
and then

var nCount = MyList.#items[0].nodes.length

if (nCount >= 2) then


for nItem = nCount downto 1 step 2 do
xfa.host.messageBox( MyList.#items[0].nodes.item(nItem - 1) )
endfor
endif

JavaScript Syntax
for (var i = 1; i <= 10; i++)
{
MyList.addItem(i);
}
(in this case, the curly braces are optional but I think this is better style) and then

var nCount = MyList.resolveNode("#items[0]").nodes.length;

if (nCount >= 2)
{
for (var nItem = nCount; nItem >= 1; nItem - 2)
{
xfa.host.messageBox(
MyList.resolveNode("#items[0]").nodes.item(nItem - 1) );
}
}

SOME USEFUL LINKS


https://blogs.sap.com/2016/05/12/adobe-form-using-javascirpt/

https://blogs.sap.com/2015/07/15/overview-on-scripting-languages-for-adobe-forms-beginners/

https://blogs.sap.com/2013/04/03/using-java-script-in-sap-adobe-forms-to-dynamically-select-logo-
image-on-the-basis-of-a-field-value/

https://answers.sap.com/questions/1099105/java-script-for-adobe-forms.html

https://answers.sap.com/questions/3353467/how-to-use-scripting-in-interactive-form.html
https://answers.sap.com/questions/6315035/adobe-forms-syntax-for-if-statement-in-javascript.html

https://answers.sap.com/questions/9494987/hide-a-page-in-adobe-forms-with-javascript.html

https://forums.adobe.com/thread/2626002

http://saptechnical.com/Tutorials/AdobeForms/Hide/Page3.htm

https://acrobatusers.com/forum/forms-livecycle-designer/making-bold-calculated-field-through-
scriptjavascript/

https://forms.stefcameron.com/2006/09/14/formcalc-expressions-if-and-for/

https://sapyard.com/sap-adobe-forms-practical-use-case-of-formcalc-and-javascript/

https://blogs.sap.com/2016/09/14/manipulate-reference-fields-in-script-for-adobe-forms/

http://www.adobepress.com/articles/article.asp?p=1021020&seqNum=4

https://www.apprisia.com/blog/sap-netweaver/use-of-java-script-and-form-calc-in-adobe-interactive-
form/

You might also like