WTF Solution

JavaScript Code and FormCalc for Adobe form in SAP 2026

Here, I have written some basics to advance JavaScript code and FormCalc code for Adobe Form. Script like if-else, looping the table, hiding the field, splitting the string, rounding up, changing the caption, font, colour, and border in dynamic. Do you want to know how to create a custom Form in SAP Public Cloud?

If Else Statement in JavaScript code

if (inputStr2.isNull || inputStr2 = "" || inputStr2 = " ")  {
Form.bdyMain.f3.CheckedBy.rawValue = inputStr;
Form.bdyMain.f3.Authorised.rawValue = inputStr1;
}

Hide the field based on the condition using JavaScript code

Method 1 (Hidden or Visible)
Form.cpage1.table.tblRemarkRowTable.rowItem.presence = "hidden" ;

Method 2 (Inactive or Active)
if ( grossWeight == null || grossWeight <> null and grossWeight == 0 ) {
  this.presence = "inactive"; }
else {
  this.presence = "active"; }

Method 3 (Formcalc language)
if ($.isNull or $.rawValue eq "" or $.rawValue eq " ") then
$.presence = "hidden"
endif

Method 4 (Hide Table)
if( Form.bdyMain.frmTableBlock.tblRemarkRowTable.resolveNodes("rowItem[*]").length < 1 ) then
  this.presence = "hidden";
endif

Concat two fields

$.rawValue = Concat(this.rawValue," GST : 33AAGCN7620Q1Z1") // (Formcalc Language)
or
this.rawValue = this.rawValue && '%'. (JavaScript Language)

Convert Amount to Amount in Word using JavaScript

var y;
var z;
z = sf1.NumericField1.rawValue; // Amount in Number (Input)
sf1.TextField1.rawValue= WordNum(z,2);
y = sf1.TextField1.rawValue;
y = Replace(y,"Dollars","Rupees");
y = Replace(y,"Cents","paise");
sf1.TextField2.rawValue = y; // Amount in Word (Output)

Split and pass the value to the fields

var input= this.rawValue.split(" "); 
var inputStr=input[0];
var inputStr1=input[1];
Form.cpage1.TOP.LEFT_ADDRESS.EXP_Address.frmSupplierAddress.txtLine5.rawValue = inputStr1

Slice the String or cut the String

var str = this.rawValue ; 
this.rawValue = str.slice(0, 4);
or
this.rawValue = str+0(4);

Note: Cut the First 4 characters of a string.
0 is the starting index value, and 4 is the ending index value. 

Round up the value

Round up code Round(12.389764537, 4)  Output = 12.3898

Count Serial Number

this.rawValue =  $.parent.parent.parent.index
Note: If the serial no. field has three parent subforms.

Calculate Total Amount

this.rawValue = xfa.resolveNodes("Form.cpage1.table.tblRemarkRowTable.rowItem[*]").length; // JavaScript
Note: Using JavaScript and form: ready
or
$.rawValue = Sum(Form.cpage1.table.tblRemarkRowTable.rowItem[*]) // FormCalc Language
Note: Using FormCalc Language and form: Calculation

Set the value on the specific row of the table using the index no

xfa.resolveNode("Form.cpage1.table.rowItem[" + 0 + "].container_no").rawValue = "3";
Note: "0" is the index no.

Go to the Next Line or a New Line

$.txtLine2 = concat($.txtLine2.rawValue,"\u000a",$.txtLine3.rawValue;  
Note: "\u000a" is for new line ( only for formcalc language support)

Add the Number of days in a Date

var d = Form.frmBody.frmLabelWrap.ExpDt.formattedValue
var year = substr(d,7, 4)
var y1 = mod(year, 4)
var days = 1
if(y1 == 0 ) then days = 365 endif
if(y1 == 1 ) then days = 366 endif
var dnum = Date2Num(d, "DD.MM.YYYY") + days
$.rawValue = num2date(dnum, DateFmt(2))

Loop the table in JavaScript

var item_data = xfa.resolveNodes("Form.cpage1.table.tblRemarkRowTable.rowItem[*]");
var sl = this.Cell1.rawValue; // current row value
for (var i = 0; i < item_data.length; i++) {
  lv_slno = xfa.resolveNode("Form.cpage1.table.tblRemarkRowTable.rowItem[" + i + "].Sl_no").rawValue; // this is specific row value
  if(lv_slno == sl) { 
     sl_inx = i; 
     break;
  }
}

Change Field Caption using JavaScript in Adobe Form

$.caption.value.text.value = "GSTIN:" ;
or
TextField1.caption.value.text = "Dynamic caption"
TextField1.assist.toolTip = "Better explanation"

Change Field Font using JavaScript

TextField1.caption.font.typeface = "Times New Roman"

Change Font colour using JavaScript

StaticText1.caption.font.fill.color.value = "200,0,0"  ;RGB values

other Properties
StaticImage1.rotate = "90"
StaticText1.x = "12cm"

Remove the border using JavaScript

field.border.presence = "hidden";
this.border.getElement("edge",2).presence = "invisible" or "hidden"
this.board.edge.presence = "hidden";

Reference link: Adobe form JavaScript code, Sample code from Adobe

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top