Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
prajeshdesai
Contributor
80,407
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

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

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

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


Loop through all controls (fields) in adobe forms

A lot more to explore, will share with you soon.

Best Regards.

Prajesh Desai
22 Comments
Former Member
0 Kudos

Quite helpful for beginners

petrsourek
Explorer
0 Kudos

Not only for beginners, since I have returned after 2 years to the form scripting, this is helpful for me to get correct syntax, thank you Prajesh *THUMBS UP*

prajeshdesai
Contributor
0 Kudos

Yahhh Petr, Thanks..

Former Member
0 Kudos

Great resource for beginner.

What about change Money symbol based on currency?  I used pattern but always print as $ even in Yens.  The format for yens is correct (No decimals), but the money symbol is '$'.  I resolved this by using text field and write to the text field, but I am curious to see if we can use pattern for multiple currency with the Monetary symbol before the Amount.

Another challenges for beginner like me is I need to switch tray to print on different color paper.  I have 5 Master Page and for the first Master page it have to be in Blue color and the rest will be on white color.  How do you write script to switch print tray?

Thanks,

prajeshdesai
Contributor
0 Kudos

Check this document: Dynamic Currency Symbol With Patterns for Adobe Forms

Will try for tray settings.

Former Member
0 Kudos

Hi Prajesh,

Thank you for taking time to post the page on dynamic currency.  This help me a lot.  Can't wait for tray setting sample. 

pradeep_sampath
Explorer
0 Kudos

Hi Prajesh,

This document looks very helpful. I really appreciate your effort.

After a long time, i am currently working on adobe form using some javascript coding(Ain't much familiar with Java script). I have a table with 6 columns. Based on one column(Status Field), I would like to fill some colors in background for another column. I tried applying your snippet in initialize event. Unsuccessful. Could you help me on this.

Below are code

data.Page3.Policy.LT_ELEMENT[0].DATA::ready:form - (JavaScript, client)

var numrows = xfa.resolveNodes("data.Page3.Policy.LT_ELEMENT[0].DATA[*]");

var rowFillColor;

var lv_status;

for (var i=0; i<numrows; i++)

{

lv_status = xfa.resolveNode("data.Page3.Policy.LT_ELEMENT[0].DATA["+i+"].STATUS_1").rawValue;

if (lv_status == "Completed")

{

rowFillColor =  "153,153,153";

xfa.resolveNode("data.Page3.Policy.LT_ELEMENT[0].DATA["+i+"].ELEMENT_1").this.fillColor = rowFillColor;

}

else if (lv_status == "In Process")

{

rowFillColor =  "231,254,254";

xfa.resolveNode("data.Page3.Policy.LT_ELEMENT[0].DATA["+i+"].ELEMENT_1").this.fillColor = rowFillColor;

}

}

Here, based on STATUS_1 value, we have color the ELEMENT_1 column .

bruno_moreira
Explorer
0 Kudos
Hello Prajesh,

i just came here to say very thank to you...your post helped me a lot.

Bruno!
prajeshdesai
Contributor
0 Kudos
Happy to see helpful to you. 🙂
maftunahmed
Explorer
0 Kudos
Hi expert,

 

Please help me out, what is "xfa" in your syntax??

my interface structure name is "DATA". and I want on one of the fields of "DATA" structure which is "Flag", I want subform to get hide or show. (When its value 'X' then visible else visa verse.

Will anyone suggest?
prajeshdesai
Contributor
The xfa object is the root node for the xfa model where your interface data are stored.

Have a look at this,



So in above example if i want to refer 1st row from table IST_CHAR20,
var LV_DATA = xfa.resolveNode("$record.IST_CHAR20.DATA[1].ITEM").value;

 

Hope this helps.

 
maftunahmed
Explorer
0 Kudos
Thanks, Prajesh (Y).
Former Member
0 Kudos
Prajesh, I am having a ZCI layout where i need to display some words in a sentence in bold. It works perfectly fine for normal layout. But in ZCI it dosent render the tags properly. Any help ?
0 Kudos
Thank you so much sir , Your  post helped me a lot.
prajeshdesai
Contributor
0 Kudos
Happy to see helpful to you. ?
former_member652492
Discoverer
0 Kudos
Hi, Prajesh.

I am a new adobe and i am only person that working adobe in a project.

I have made invoice and invoice can be multiple. So I have made Key Table and loop it for data.

i am wondering how to count page dynamically whenever key is changed.

ex) first invoice overflowed.. so page 1 of 2 .. page 2 of 2.

second invoice overflowed.. so page 1 of 3 .. page 2 of 3. .. page 3 of 3.

.

.

.

please help me out
pmcfarling
Participant
0 Kudos
Saved my life. Thanks!
0 Kudos
Hi Prajesh,

I am trying to increase the size of a field in the table but it is not increasing . Please help!

data.#subform[0].#subform[3].Table6[0].Row1.Cell4::initialize - (JavaScript, client)

this.cell4.font.weight ="bold";
this.cell4.font.size ="8pt";

Kiran pulipaka

9347668988
KrittinE
Participant
0 Kudos

Hi Expert,


I don't know why 'undefined' occur in the below picture.


Kindly help or suggest me.


 

Thank,


Mimi


clemenssss
Explorer
0 Kudos
Thank you for all the effort - it helped me to get through the trouble of using javascript withoout any debugging or other help.

Specially without the help of debugging and without the ability to issue messages or log anything, it is really hard. I still don't understand why you assign the controlling value to a variable first befor using it.

I had the requirement to hide a barcode output under certain conditions. So I included the field ZPRINT_BARCODE_LE of type flag in the interface structure ZEXT,

My javascript for the initialize section of the barcode field looks like this:
 data.#subform[0].ZNLENR0::initialize - (JavaScript, client)
if (xfa.record.ZEXT.ZPRINT_BARCODE_LE.value != "X")
{this.presence = "hidden"}


It works to access the field by prefixing it with xfa.record. Access using rawValue property did not work, property value did the trick.

I could not find good documentation. "xfa" (XML Forms Architecture) addresses the whole form, whereas "record" addresses the data/import area, I guess al data defined in context are properties of the record object.

How coul I possibly generate output or log data direcly from the embedded javascript? Does ADOBE provide any documentaion about xfa, record and so on, where can I find more on sap.com?

Thank you, Clemens

 
0 Kudos
Hi Prajesh,

it will applicable to odata based adobeform also?

I want to hide a subform based on systemid which has image .

I tried like this but not working. is there any way to do scripting for odata based adobeform?

Please tell me is it possible to debug script in adobeform?

Please share your idea on this.

thanks,

Rajeshwari
Sanjeev_Bhogan
Discoverer
0 Kudos

Hello @prajeshdesai ,

Thank you for the wonderful blog!

I want to read field Loan Recovered and based on the value I want to modify the value of the Loan Balance field.

Sanjeev_Bhogan_0-1745229656575.png

My code is for Loan Balance field is:

var x = LoanRecovered.rawValue;

if (  x == "0.00" || x == "0"  ) {
this.rawValue = null;
}

But its not making the value of Loan Balance as null.

Am I reading the fields in an incorrect way? Please help

Thank you

 

Labels in this area