Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Is it possible to call a JavaScript function from a FormCalc script?

Avatar

Level 5
Greetings:

I am wondering if there is a way to call a function coded in JavaScript from a field event that is coded in FormCalc in Designer 8.

If so, I should be able to reference the same global variables in each language correct?



Best Regards:

Mark
8 Replies

Avatar

Level 4

Hey Mark - did you ever get an answer to this?  I am doing the same thing and I don't know if that is the reason that the script isn't working.

Avatar

Level 10

You can execute the code written in FormCalc in a field from script written in JavaScript from a different field.

For example I wrote this script in NumericField2 and language is Java Script:

     NumericField1.execEvent("click");

Where NumericField1 has code written in click event and language is FormCalc..

This way you can execute events from controls irrespective of language they have written.

Hope this helps.

Thanks

Srini

Avatar

Level 4

Thanks Srini!

That is what I want to do.  I have tables that I have simple FormCalc calculations on to total the fields.  I want to then compare the totats of the fields to make sure they are equal.  That is where I am using the if else statment with JavaScript.  But for some reason it isn't working.It is the first part of my IF statement that doesn't do anything - when I go to the form and make them all equal I don't get the "boo" message (I am just trying to learn )

thanks!

Jodi

var myDoc = event.target;

var CashCheckTotal = myDoc.getField("form1[0].#subform[0].CalculatedCashCheckTotal[0]");

var DescTotal = myDoc.getField("form1[0].#subform[0].CalculatedDescriptionTotal[0]");

var FoapTotal = myDoc.getField("form1[0].#subform[0].CalculatedFoapTotal[0]");

var curDate=new Date();

var PartNetID = myDoc.getField("form1[0].#subform[0].NetID[0]").value;

var dialogTitle = "Please Confirm that the email was sent and the form was printed";

var defaultAnswer = "Yes";

var f = myDoc.getField("form1[0].#subform[0].Campus[0]");

var cbStatus1 = (f.isBoxChecked(0)) ? "OK" : "not";

var cbStatus2 = (f.isBoxChecked(1)) ? "OK" : "not";

var cbStatus3 = (f.isBoxChecked(2)) ? "OK" : "not";

if("CashCheckTotal" == "DescTotal"


& "DescTotal" == "FoapTotal")
    {xfa.host.messageBox("Boo")}
   
else {xfa.host.messageBox("Totals are not equal or are zero:\n" + "Calculated Description Total(A), Calculated Cash/Check Total(B) and Calculated CFOAPAL Total(C) must be equal.");}

Avatar

Level 10

Jodi,

    The functions that you used inside your code are used in Acroforms Java Script. But they may not work in LiveCycle Java Script..

    I modified your script.. Try it in your form..

var CashCheckTotal = xfa.resolveNode("form1[0].#subform[0].CalculatedCashCheckTotal[0]").rawValue;
var DescTotal = xfa.resolveNode("form1[0].#subform[0].CalculatedDescriptionTotal[0]").rawValue;
var FoapTotal = xfa.resolveNode("form1[0].#subform[0].CalculatedFoapTotal[0]").rawValue;

var curDate=new Date();
var PartNetID = xfa.resolveNode("form1[0].#subform[0].NetID[0]").rawValue;


var dialogTitle = "Please Confirm that the email was sent and the form was printed";
var defaultAnswer = "Yes";
var f = xfa.resolveNode("form1[0].#subform[0].Campus[0]").rawValue;

var cbStatus1, cbStatus2, cbStatus3

if(f = 0){
   cbStatus1 = "OK";
   cbStatus2 = "not";
   cbStatus3 = "not";
}

if(f = 1){
   cbStatus2 = "OK";
   cbStatus1 = "not";
   cbStatus3 = "not";
}

if(f = 2){
   cbStatus3 = "OK";
   cbStatus1 = "not";
   cbStatus2 = "not";
}
   
if((CashCheckTotal == DescTotal) && (DescTotal == FoapTotal))
xfa.host.messageBox("Boo");

else
xfa.host.messageBox("Totals are not equal or are zero:\n" + "Calculated Description Total(A), Calculated Cash/Check Total(B) and Calculated CFOAPAL Total(C) must be equal.");

Thanks

Srini

Avatar

Level 4

Awesome!

What is the difference if I use

var CashCheckTotal = CalculatedCashCheckTotal.rawValue

and

var CashCheckTotal = xfa.resolveNode("form1[0].#subform[0].CalculatedCashCheckTotal[0]").rawValue;

One last question - How to I write a script to make sure they fill in a field?

I can't figure it out!  I am trying to also create an if else statement that if a field is blank they get an error message.

Thanks so much for the help!

Jodi

Avatar

Level 10

Jodi,

       

What is the difference if I use

var CashCheckTotal = CalculatedCashCheckTotal.rawValue

and

var CashCheckTotal = xfa.resolveNode("form1[0].#subform[0].CalculatedCashCheckTotal[0]").rawValue;

Srini:

There is no difference.. I prefer to use the fist one though. The second one is used to reseove a field in your form that has dynamic sections added at the run time..

One last question - How to I write a script to make sure they fill in a field?

I can't figure it out!  I am trying to also create an if else statement that if a field is blank they get an error message.

Srini:

Place the following code in the exit event of the field. Choose the language as JavaScript.

if(this.rawValue == null || this.rawValue == ""){

     xfa.host.messageBox("Field cannot be empty");

     xfa.host.setFocus(this);

}

Thanks

Srini

Avatar

Level 4

Hi Srini - I lied - I have another question - I tried what you gave me but did it a little different and I am getting an error that says TodayDate has not properties.  I am using it on the click of the button.  Any idea why it doesn't work.

var oDoc = event.target;
var CashCheckTotal = CalculatedCashCheckTotal.rawValue
var DescTotal = CalculatedDescriptionTotal.rawValue
var FoapTotal = CalculatedFoapTotal.rawValue
var TodayDate = TodayDate.rawValue

if (CashCheckTotal == DescTotal & DescTotal == FoapTotal & CashCheckTotal > 0)
    {if (TodayDate.rawValue == null || TodayDate.rawValue == "") {xfa.host.messageBox("Need Date")}
     else {xfa.host.messageBox("Good")}
     }  

else {xfa.host.messageBox("Hoo")};

Avatar

Level 4

Srini! I figured it out!  Thank you so much for you help!