Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Validate required fields on Print Form button

Avatar

Former Community Member
I have a form and when the user clicks the "Submit by Email" button, all fields that are set as User Required are verified as being filled in before moving on to the email window. I also have a "Print Form" button. When this is clicked the fields are not tested for valid data before the print window appears. How can I check that all required fields are entered before the user prints?
5 Replies

Avatar

Level 5
You have to write your own script to verify all the required fields are filled-in. Moreover I will start with regular button no the Print Button provided in the Library.



Here is a sample script I used on the 'click' event of the regular button which is similar to your requirement.



var CN

var CA

var CC

var CZ

var FN

var Cmsg

if (HasValue(form1.#subform[0].Table4.Row1.Client_Name)) then

CN = ""

else

CN = "Client Name\u000a"

Cmsg = CN

endif

if (HasValue(form1.#subform[0].Table4.Row2.Client_Address)) then

CA = ""

else

CA = "Client Address\u000a"

Cmsg = Concat(Cmsg, CA)

endif

if (HasValue(form1.#subform[0].Table4.Row3.Client_City)) then

CC = ""

else

CC = "Client City\u000a"

Cmsg = Concat(Cmsg, CC)

endif

if (HasValue(form1.#subform[0].Table4.Row4.Client_Zip)) then

CZ = ""

else

CZ = "State/Zip or Province/Postal Code\u000a"

Cmsg = Concat(Cmsg, CZ)

endif

if (HasValue(form1.#subform[4].For_Name)) then

FN = ""

else

FN = "For Client Name"

Cmsg = Concat(Cmsg, FN)

endif



if (Cmsg <> "") then

Cmsg = Concat("Print operation can not be completed as following information is missing.\u000a", Cmsg)

xfa.host.messageBox(Cmsg, "Missing Value", 0, 0)

else

form1.#subform[0].Button1.presence = "hidden"

//Button1 is Prnit button in this case. You can also

//set it to visible(but Don't print) on the Object--field tab.

xfa.host.print(1, "0", "2", 0, 1, 0, 0, 0)

endif



Hope this help.



Good Luck,

SekharN.

www.lawson.com

Avatar

Level 1

Thanks so much for the useful post SekharN.

It worked great as a FormCalc script. How easy is it to convert to Javascript? What I wanted to utilize this with was

app.execMenuItem("SaveAs"); on a button.

FormCalc didn't have an equivalent unfortunately....

Right now I have your script on mouseEnter, then onClick I use the app.execMenuItem("SaveAs"); on a button as javascript. If the validation fails, it never lets you get to the on Click which is good.

I would much rather have it as a conditional on click though. The mouseEnter validation works as a band aid but it's not pretty.

Thanks in advance.

-Jon

Message was edited by: jdoranz5150

Avatar

Level 5
Hi Angie,

The code you suggested does not help Bill. Default 'Print' button do not validate any fields before it brings up print screen. But default 'Email' button do validate all the required fields just before it submits. That is the difference. Can you try this and see the results.... save the FieldRequired.pdf from the URL you provided. Open the file in LC Designer and Add 'Print Button' from Library and then save. Open in the file in Adobe Reader. Click 'Set as Required' then 'Print Form'. No thing stops you form printing. But Bill wants to stop printing at this point when required field is with null data.

Your suggestion does not apply for the requirements he had.



Take it easy,

SekharN.

www.lawson.com

Avatar

Former Community Member
Bill did you get this to work yet, I have the same thing I need to happen check for empty fields before printing