Expand my Community achievements bar.

SOLVED

How to Execute a code in form postSubmit event

Avatar

Former Community Member

Dear all,

I have a simple code which is executed perfectly when I put it in form :preSubmit: event but when i moved it to the :postSubmit: event it doesn't work at all .

Please let me know where to put my code if I need it just to be executed once the form submitted ??

Thanks in advanced,

Mohammed Al-Mosleh

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Try using this code:

var vMsg = ""; //message to display for the missing required fields

var successflag = 1; //flag to determine if any required field is null

//validate all required text fields

for (var nPageCount=0; nPageCount<xfa.host.numPages; nPageCount++) {

var oFields = xfa.layout.pageContent(nPageCount,"field");

var nNodesLength = oFields.length;

for (var nNodeCount=0; nNodeCount<nNodesLength; nNodeCount++) {

if (oFields.item(nNodeCount).mandatory == "error" ){

if (oFields.item(nNodeCount).rawValue=="" || oFields.item(nNodeCount).rawValue==null){

vMsg += oFields.item(nNodeCount).name + ", ";

successflag = 0;

}

}

---------write your code

if (successflag == 1)

{  

execute the insert into database code

  }

else

{

  xfa.host.messagebox(vmsg); //displays the missing field names

}

Regards,

Chaitanya

View solution in original post

9 Replies

Avatar

Former Community Member

Hi,

What code do you want to execute at preSubmit/postSubmit event.

Regards--

Chalukya.

Avatar

Former Community Member

Hi Chalukya,

I' am calling a web services to save the request data into the database and to update the request status too.

// insert request main data

Main.header.GetMaxRequestNumber.execEvent("click");

Main.header.InsetRequest.execEvent("click");

// end of insert request main data

// end of insert request main data

If i put this code in the preSubmit event it works works and the webservices called and the data saved in the database, but if i moved it to the postSubmit event it doesn't work and nothing saved in the database.

The problem of putting it in the preSubmit is when the user misses to enter any required field the data will saved and the form shows the required fields messege and once the user fill the missing field and press submit the code will executed again.

I just want this code to be executed if and only if the submit works without warning.

Regards,

Mohammed

Avatar

Former Community Member

Still waiting for your help !!

Thanks in advanced.

Avatar

Former Community Member

I tried to read all posts and i didn't find a solution for this issue , i wondering if any one have any ideas or suggestions!!!

Avatar

Former Community Member

Hi Mohammed,

You code will not work in the PostSubmit or postSave events as postSubmit event scripts are executed after the complete submit was happened.

It's some what similar to postSave event where you want to confirm the user that submit or save events executed successfully. If you try to put any message box in the postSubmit event, you can see the behaviour of the event.

I made a sample form why post submit dont works.  I kept the message box and assigned a value to text field in the post submit events. When I click on the submit, first the form will be submitted to email, where you dont see the value in the text field in the xml, then in the pdf you see that the value is assigned to the text field.

So, try to write all your scripts in the Pre events. May be xfa.event.cancelAction can help you to not to repeat your code execution twice when you are writing in the pre events.

Hope this helps.

Regards,

chaitanya

Avatar

Former Community Member

Thanks chaitanya,

As per your reply it seems that i should put my code in the presubmit but before executing my code i should write a code to make sure that all required fields is entered.

so the question will be how to make sure that all required fields filled in my form before executing the insert into database code.

i will write the code in english here and i need to know how to convert it to javascript please:-

if (all required fields != null)

{

execute the insert into database code

{

else

{

show the required fields message and cancel from submitting (i think this code will be executed automatically without writing any code)

}

Regards,

Mohammed Al-Mosleh

Avatar

Correct answer by
Former Community Member

Try using this code:

var vMsg = ""; //message to display for the missing required fields

var successflag = 1; //flag to determine if any required field is null

//validate all required text fields

for (var nPageCount=0; nPageCount<xfa.host.numPages; nPageCount++) {

var oFields = xfa.layout.pageContent(nPageCount,"field");

var nNodesLength = oFields.length;

for (var nNodeCount=0; nNodeCount<nNodesLength; nNodeCount++) {

if (oFields.item(nNodeCount).mandatory == "error" ){

if (oFields.item(nNodeCount).rawValue=="" || oFields.item(nNodeCount).rawValue==null){

vMsg += oFields.item(nNodeCount).name + ", ";

successflag = 0;

}

}

---------write your code

if (successflag == 1)

{  

execute the insert into database code

  }

else

{

  xfa.host.messagebox(vmsg); //displays the missing field names

}

Regards,

Chaitanya

Avatar

Former Community Member

Many Thanks Chaitanya ,

Really appreciate your help.

Kind Regards,

Mohammed Al-Mosleh

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----