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.

Please Help with Code Triggering Two Things!

Avatar

Level 3

Is there a way to make the code below NOT bring up the prompt "Please Complete Customer B Information” if you select
“No” to the first question?  If “No” is selected I would like the form to print, which it will but it also brings up the prompt "Please Complete Customer B Information”.

Thanks for any help!!

var answer=xfa.host.messageBox("Is this a Joint Account?","Confirmation Required !!!",2,2)

if(answer == 3)

{

PrintButton1.execEvent("click");

}

if(answer == 4)

{

var answer=xfa.host.messageBox("Have You Completed Customer B Information?","Confirmation Required !!!",2,2)

}

if(answer == 3)

{

var answer=xfa.host.messageBox("Please Complete Customer B Information!","",1)   

}

if(answer == 4)

{

PrintButton1.execEvent("click");

}

9 Replies

Avatar

Level 10

Hi,

I hope I understood you workflow.


if (xfa.host.messageBox("Is this a Joint Account?","Confirmation Required !!!", 2, 2) === 4 ) {


  if (xfa.host.messageBox("Have You Completed Customer B Information?","Confirmation Required !!!", 2, 2) === 4) {


  PrintButton1.execEvent("click");


  } else {


  if (xfa.host.messageBox("Please Complete Customer B Information!", "" , 1, 0) === 1) {


  PrintButton1.execEvent("click");


  }


  }


} else {


  PrintButton1.execEvent("click");


}


For future use:

You cannot use a variable name twice!

Avatar

Level 3

Thanks for the reply.  What you suggested almost worked, however once you select OK to the prompt "Please Complete Customer B Information", it prompts you to print where I just want it to cancel if you select OK.

I removed, PrintButton1.execEvent("click") from

if (xfa.host.messageBox("Please Complete Customer B Information!", "" , 1, 0) === 1) { 

  PrintButton1.execEvent("click"); 

and it worked as I intended.

However, messing around I removed the

 

  } 

  }

and it didn't work so I added them again an it worked fine.  Why are those needed??

Thanks again!!

Avatar

Level 10

Ok,

so you simply want to show the message without any further action? That wasn't clear to me in your script.

This script now should do what you want.


if (xfa.host.messageBox("Is this a Joint Account?","Confirmation Required !!!", 2, 2) === 4 ) { 


     if (xfa.host.messageBox("Have You Completed Customer B Information?","Confirmation Required !!!", 2, 2) === 4) { 


          PrintButton1.execEvent("click"); 


     } else


          xfa.host.messageBox("Please Complete Customer B Information!", "" , 1, 0);


     } 


} else


     PrintButton1.execEvent("click"); 


}


Avatar

Level 3

No problem, and I was able to get the script to work by removing, PrintButton1.execEvent("click") after "Please Complete Customer B Information!", however, I had to keep this in order for it to work,

 

  } 

  }

After looking at your second code it looks like I needed to remove the first curly bracket { .

Any idea why the following code doesn't work?  I created a checkbox, and one text field and a submit by email button.  I made the textfield required and put the code on the click of the check box, and the language is javascript.  If I check the check box it and put nothing in the text field it still want's to send.

Is there anyway to apply this to the print or a standard button??  This might be a way to specify if it's a joint account.  If it is, then other fields will be required, if not then customer b information wouldn't be needed.  I have a form that requires customer a information and if it's a joint account then customer b information would be required otherwise it's not required.

if (this.rawValue==1)

{

   this.parent.TextBox1.mandatory = “error”;

}

else

{

   this.parent.TextBox1.mandatory = “disabled”;

}

//To make the Field optional change the above statement to: this.parent.TextField1.mandatory = “warning”;

Do you know how to turn the following into javascript.  I have this on the mouse down in formcalc and the initial code you helped with on the mouse up which triggers the customer b prompts.  If it was in javascript, I might be able to get it to work in conjunction with the above codes.

if ((Name.rawValue == null) or (Address1.rawValue == null) or (Address2.rawValue == null) or (DOB.rawValue == null)
or (SSN.rawValue == null) or (Phone.rawValue == null) or (Email.rawValue == null) or (Occupation.rawValue == null)
or (Other_Describe.rawValue == null) or (ID_Number.rawValue == null) or (Date_of_Issuance.rawValue == null)
or (Date_of_Expiration.rawValue == null) or (State_of_Issuance.rawValue == null) or (OFAC_comparison_date.rawValue == null)
or (OFAC_results.rawValue == null) or (Credit_bureau_date.rawValue == null) or (Account_type_1.rawValue == null)
or (Account_number_1.rawValue == null) or (Account_type_2.rawValue == null) or (Account_number_2.rawValue == null)
or (Account_type_3.rawValue == null) or (Account_number_3.rawValue == null)

or (CheckBox1.rawValue == "0") & (CheckBox2.rawValue == "0") or (CheckBox3.rawValue == "0") or (CheckBox4.rawValue == "0")) then
xfa.host.messageBox("STOP! Please complete all required fields.")

endif

You've been very helpful!

Avatar

Level 3

I'm trying to create a fillable form for new accounts which will check for required fields before printing and prompt the user if there are required fields missing and determine if it's a joint account. 

I've almost got it and maybe what I want isn't possible.  For the test I have two text fields and 4 check boxes.

I got the required fields working by using the following javascript on the “Click” function;

if ((TextField1.rawValue == null) || (TextField2.rawValue == null) || (CheckBox1.rawValue == "0") && (CheckBox2.rawValue == "0") || (CheckBox3.rawValue == "0") || (CheckBox4.rawValue == "0"))

{
xfa.host.messageBox("STOP! ALL fields must be completed in order to print this form")
}

else
{
PrintButton1.execEvent("click")
}

If they complete all the required fields we need to find out if it’s a joint account and if it is we need to remind the user to fill out the required information for customer b.  I’ve kind of got that working by putting the following javascript on the “Preprint” function;

if (xfa.host.messageBox("Is this a Joint Account?","Confirmation Required !!!", 2, 2) === 4 ) {   

if (xfa.host.messageBox("Have You Completed Customer B Information?","Confirmation Required !!!", 2, 2) === 4) {   

PrintButton1.execEvent("click");   

} else {   

xfa.host.messageBox("Please Complete Customer B Information!", "" , 1, 0); 

}   

} else {   

PrintButton1.execEvent("click");   

The problem is, that if you say “No” that you have not completed customer b information, you get prompted “Please Complete Customer B Information!” but when you click OK is brings up the print dialog box and I would like it to cancel the print job if possible.  I really don’t understand what I’m doing, I just cut and paste and hope for the best.  However, I was able to turn the code on the “click” function from formcalc code into javascript by replacing, or with || the &’s with && and adding the curly brackets {}.  Not sure if it’s the correct way but it seems to be working.

I found a video for the following code which I put on a checkbox but I can't seem to get it to function with a standard button, only a submit by email button.  This might work well as I could have that on the form and if it's selected it would make the customer b fields required.

if (this.rawValue==1)

{

   this.parent.TextBox1.mandatory = “error”;

}

else

{

   this.parent.TextBox1.mandatory = “disabled”;

}

//To make the Field optional change the above statement to: this.parent.TextField1.mandatory = “warning”;

Avatar

Level 10

Sorry for saying so, but you scripting looks messy.

I'm suggesting that you use the JS-Lint tool to debug your scripts.

To check fields vor the null value you either have to use the operator === instead of == or you simply use the integrated method isNull.


if (Textfield1.isNull || TextField2.isNull || (CheckBox1.rawValue == "0" && CheckBox2.rawValue == "0") || ChecBox3.rawValue == "0" || ChecBox4.rawValue == "0" ) {


    xfa.host.messageBox("STOP! ALL fields must be completed in order to print this form");


} else {


    PrintButton1.execEvent("click");


}


Also, as you use the script with the question in the prePrint event you have already triggered the print process.

That's way you'll see the print dialog o matter what answer you select.

To cancel the printing you have to add the cancelAction method, inform the host, that the print pocess will be aborted.


if (xfa.host.messageBox("Is this a Joint Account?","Confirmation Required !!!", 2, 2) === 4 ) {  


  if (xfa.host.messageBox("Have You Completed Customer B Information?","Confirmation Required !!!", 2, 2) === 4) {  


  xfa.host.messageBox("PRINT"); 


  } else {  


  xfa.event.cancelAction = true;


  xfa.host.messageBox("Please Complete Customer B Information!", "" , 1, 0);


  }  


} else {  


  xfa.host.messageBox("PRINT"); 


}


Hope this helps!

Avatar

Level 3

No offense taken. I have no clue to what I'm doing other then copy, pasting and tweaking. I'll take a look at the JS-Lint tool. 

I figured out the print issue and got things working and then the form needed to be expanded.  I expanded the form and put the buttons on the second page but nothing happens, if I move them to the first page it works as it should.

I'll do a search to see if I can find the answer it's just that you've been so helpful I thought I'd ask.

Avatar

Level 3

One other question which I can't seem to find an answer for.

How do you create a pop up message when the form opens?

I have a form that does that but I can't find what triggers it.  I've looked at all the events and scripts but I see nothing.  I thought maybe it was on the docReady but there is nothing there.

I created a new document and put this, app.alert("Please Complete All Required Fields Highlighted Red", 3); on docReady which works but the other document doesn't have that yet there is a pop up message when the documents opens.

Avatar

Level 10

Maybe an validation message of a field set to be required.

You can find those settings Value tab of the Object palette.