Tags: apex, code, conditions, database, javascript, met, mysql, oracle, page, performs, process, sql, submits, validation

Javascript and Apex Process

On Database » Oracle

13,418 words with 1 Comments; publish: Fri, 15 Feb 2008 11:56:00 GMT; (25078.13, « »)

Hi All,

I am new to using Javascript and I wrote some code that performs data validation. If all conditions are met the javascript submits the page. The code works perfectly, but I also have a process that is processed on submit - after computations and validations that runs a PL/SQL statement to insert the form's information into a table. The javascript seems to run fien, but when the page is submitted from the javascript, the apex process does not run. Does anyone know why this is happening?

The javascript is included below...

Thanks!

<script type = "text/javascript">

//Function to perform data validation

function checkNull(){

var x = 0;

var y = 0;

var z = 0;

var j = 0;

var k = 0;

var m = 0;

var n = 0;

var p = 0;

var q = 0;

var r = 0;

var s = 0;

var regExp = /\s+/g;

var regExp_money = /\d{1,6}\.\d{2}/;

var msgbox = "The following errors have occured: \n \n"

if($x('P2_IMPACTTYPE').value == "%null%")

{

x = 1;

document.forms(0).P2_IMPACTTYPE.style.background = '#ff0000';

}

else

{

document.forms(0).P2_IMPACTTYPE.style.background = '#ffffff';

}

if($x('P2_IMPACTCATEGORY').value == "%null%")

{

x = 1;

document.forms(0).P2_IMPACTCATEGORY.style.background = '#ff0000';

}

else

{

document.forms(0).P2_IMPACTCATEGORY.style.background = '#ffffff';

}

if($x('P2_NOTIFICATIONMETHOD').value == "%null%")

{

x = 1;

document.forms(0).P2_NOTIFICATIONMETHOD.style.background = '#ff0000';

}

else

{

document.forms(0).P2_NOTIFICATIONMETHOD.style.background = '#ffffff';

}

if($x('P2_AREAHANDLING').value == "%null%")

{

x = 1;

document.forms(0).P2_AREAHANDLING.style.background = '#ff0000';

}

else

{

document.forms(0).P2_AREAHANDLING.style.background = '#ffffff';

}

if($x('P2_IMPACTDESCRIPTION').value.replace(regExp, "") == "")

{

x = 1;

document.forms(0).P2_IMPACTDESCRIPTION.style.background = '#ff0000';

}

else

{

document.forms(0).P2_IMPACTDESCRIPTION.style.background = '#ffffff';

}

if($x('P2_CONTACT').value.replace(regExp, "") == "")

{

x = 1;

document.forms(0).P2_CONTACT.style.background = '#ff0000';

}

else

{

document.forms(0).P2_CONTACT.style.background = '#ffffff';

}

if($x('P2_FMEA').value.replace(regExp, "") == "")

{

x = 1;

document.forms(0).P2_FMEA.style.background = '#ff0000';

}

else

{

document.forms(0).P2_FMEA.style.background = '#ffffff';

}

if($x('P2_DISCOVERYDATE').value.replace(regExp, "") == "")

{

x = 1;

document.forms(0).P2_DISCOVERYDATE.style.background = '#ff0000';

}

else

{

document.forms(0).P2_DISCOVERYDATE.style.background = '#ffffff';

}

if($x('P2_NOTIFICATIONDATE').value.replace(regExp, "") == "")

{

x = 1;

document.forms(0).P2_NOTIFICATIONDATE.style.background = '#ff0000';

}

else

{

document.forms(0).P2_NOTIFICATIONDATE.style.background = '#ffffff';

}

if(($x('P2_CLOSEDATE').value.replace(regExp, "") != "") &&

($x('P2_ROOTCAUSE').value == "%null%"))

{

y = 1;

document.forms(0).P2_ROOTCAUSE.style.background = '#ffff00';

}

else

{

document.forms(0).P2_ROOTCAUSE.style.background = '#ffffff';

}

if(($x('P2_CLOSEDATE').value.replace(regExp, "") != "") &&

($x('P2_ROOTCAUSE_DESCRIP').value.replace(regExp, "") == ""))

{

y = 1;

document.forms(0).P2_ROOTCAUSE_DESCRIP.style.background = '#ffff00';

}

else

{

document.forms(0).P2_ROOTCAUSE_DESCRIP.style.background = '#ffffff';

}

if(($x('P2_CLOSEDATE').value.replace(regExp, "") != "") &&

($x('P2_PRODUCT').value == "%null%"))

{

y = 1;

document.forms(0).P2_PRODUCT.style.background = '#ffff00';

}

else

{

document.forms(0).P2_PRODUCT.style.background = '#ffffff';

}

if(($x('P2_CLOSEDATE').value.replace(regExp, "") != "") &&

($x('P2_PRODUCT').value == "Med Supp") &&

(($x('P2_LOYALTY').value == "%null%") ||

($x('P2_LOYALTY').value == "")))

{

y = 1;

document.forms(0).P2_LOYALTY.style.background = '#ffff00';

}

else if ($x('P2_PRODUCT').value != "Med Supp")

{

document.forms(0).P2_LOYALTY.style.background = '#cccccc';

}

else

{

document.forms(0).P2_LOYALTY.style.background = '#ffffff';

}

if(($x('P2_CLOSEDATE').value.replace(regExp, "") != "") &&

($x('P2_REMEDIATION').value.replace(regExp, "") == ""))

{

y = 1;

document.forms(0).P2_REMEDIATION.style.background = '#ffff00';

}

else

{

document.forms(0).P2_REMEDIATION.style.background = '#ffffff';

}

if(($x('P2_CLOSEDATE').value.replace(regExp, "") != "") &&

(($x('P2_AREAIMPACTED_0').checked) ||

($x('P2_AREAIMPACTED_1').checked) ||

($x('P2_AREAIMPACTED_2').checked) ||

($x('P2_AREAIMPACTED_3').checked) ||

($x('P2_AREAIMPACTED_4').checked) ||

($x('P2_AREAIMPACTED_5').checked) ||

($x('P2_AREAIMPACTED_6').checked) ||

($x('P2_AREAIMPACTED_7').checked) ||

($x('P2_AREAIMPACTED_8').checked) ||

($x('P2_AREAIMPACTED_9').checked)))

{

z = 0;

}

else if($x('P2_CLOSEDATE').value.replace(regExp, "") == "")

{

z = 0;

}

else

{

z = 1;

}

if(($x('P2_AREAIMPACTED_6').checked) &&

(!($x('P2_MARKETINGINFO_0').checked)) &&

(!($x('P2_MARKETINGINFO_1').checked)))

{

k = 1;

}

else

{

k = 0;

}

if($x('P2_AREAIMPACTED_6').checked &&

$x('P2_CIRCULATION').value.replace(regExp, "") == "")

{

y = 1;

document.forms(0).P2_CIRCULATION.style.background = '#ffff00';

}

else if($x('P2_AREAIMPACTED_6').checked)

{

document.forms(0).P2_CIRCULATION.style.background = '#ffffff';

}

else

{

document.forms(0).P2_CIRCULATION.style.background = '#cccccc';

}

if($x('P2_AREAIMPACTED_9').checked &&

$x('P2_VENDORNAME').value.replace(regExp, "") == "")

{

y = 1;

document.forms(0).P2_VENDORNAME.style.background = '#ffff00';

}

else if($x('P2_AREAIMPACTED_9').checked)

{

document.forms(0).P2_VENDORNAME.style.background = '#ffffff';

}

else

{

document.forms(0).P2_VENDORNAME.style.background = '#cccccc';

}

if(($x('P2_CLOSEDATE').value.replace(regExp, "") != "") &&

(($x('P2_AREAACCOUNTABLE_0').checked) ||

($x('P2_AREAACCOUNTABLE_1').checked) ||

($x('P2_AREAACCOUNTABLE_2').checked) ||

($x('P2_AREAACCOUNTABLE_3').checked) ||

($x('P2_AREAACCOUNTABLE_4').checked) ||

($x('P2_AREAACCOUNTABLE_5').checked) ||

($x('P2_AREAACCOUNTABLE_6').checked) ||

($x('P2_AREAACCOUNTABLE_7').checked) ||

($x('P2_AREAACCOUNTABLE_8').checked) ||

($x('P2_AREAACCOUNTABLE_9').checked) ||

($x('P2_AREAACCOUNTABLE_10').checked) ||

($x('P2_AREAACCOUNTABLE_11').checked) ||

($x('P2_AREAACCOUNTABLE_12').checked)))

{

j = 0;

}

else if($x('P2_CLOSEDATE').value.replace(regExp, "") == "")

{

j = 0;

}

else

{

j = 1;

}

if($x('P2_AREAACCOUNTABLE_12').checked &&

$x('P2_VENDORACCOUNTABLE').value.replace(regExp, "") == "")

{

y = 1;

document.forms(0).P2_VENDORACCOUNTABLE.style.background = '#ffff00';

}

else if($x('P2_AREAACCOUNTABLE_12').checked)

{

document.forms(0).P2_VENDORACCOUNTABLE.style.background = '#ffffff';

}

else

{

document.forms(0).P2_VENDORACCOUNTABLE.style.background = '#cccccc';

}

if(Date.parse($x('P2_DISCOVERYDATE').value) > Date.parse($x('P2_NOTIFICATIONDATE').value))

{

m = 1;

}

if(Date.parse($x('P2_CLOSEDATE').value) < Date.parse($x('P2_NOTIFICATIONDATE').value))

{

n = 1;

}

if(!($x('P2_RECOVERYCOST').value.replace(regExp,"")) == "")

{

if(!($x('P2_RECOVERYCOST').value.match(regExp_money)))

{

p = 1;

}

}

if(!($x('P2_DISCOVERYDATE').value.replace(regExp,"")) == "")

{

if(isDate.call(this, $x('P2_DISCOVERYDATE').value) == false)

{

q = 1;

}

}

if(!($x('P2_NOTIFICATIONDATE').value.replace(regExp,"")) == "")

{

if(isDate.call(this, $x('P2_NOTIFICATIONDATE').value) == false)

{

r = 1;

}

}

if(!($x('P2_CLOSEDATE').value.replace(regExp,"")) == "")

{

if(isDate.call(this, $x('P2_CLOSEDATE').value) == false)

{

s = 1;

}

}

if(x==1)

{

msgbox = msgbox + "-All fields highlighted in red are required fields and must be populated before the record can be saved. \n \n";

}

if(y==1)

{

msgbox = msgbox + "-All fields highlighted in yellow are not initially required fields, but must now be populated due to dependencies on other fields. \n \n";

}

if(m==1)

{

msgbox = msgbox + "-The notification date can not be prior to the discovery date. \n \n";

}

if(n==1)

{

msgbox = msgbox + "-The close date can not be prior to the notification date. \n \n";

}

if(z==1)

{

msgbox = msgbox + "-There must be at least one area impacted prior to closing a member impact. \n \n";

}

if(j==1)

{

msgbox = msgbox + "-There must be at least one area accountable prior to closing a member impact. \n \n";

}

if(k==1)

{

msgbox = msgbox + "-Since the marketing department has been impacted by the member impact, you must select the campaign impacted by the member impact. \n \n";

}

if(p==1)

{

msgbox = msgbox + "-The recovery cost must be between 0.00 and 999999.99. \n \n";

}

if(q==1)

{

msgbox = msgbox + "-The discovery date must be a valid date and in the format mm/dd/yyyy. \n \n";

}

if(r==1)

{

msgbox = msgbox + "-The notification date must be a valid date and in the format mm/dd/yyyy. \n \n";

}

if(s==1)

{

msgbox = msgbox + "-The close date must be a valid date and in the format mm/dd/yyyy.";

}

if(x==1 || y==1 || z==1 || j==1 || k==1 || m==1 || n==1 || p==1 || q==1

|| r==1 || s==1)

{

alert(msgbox);

}

else

{

doSubmit('Add Impact');

window.location="http://fau313.uhc.com:7777/pls/apex/f?p=&APP_ID.:2:&APP_SESSION.::NO::"

alert("The member impact has been saved successfully!");

}

}

//checks to ensure that the date entered is valid and in the proper format

function isDate(dateStr) {

var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;

var matchArray = dateStr.match(datePat);

if (matchArray == null)

{

return false;

}

month = matchArray[1];

day = matchArray[3];

year = matchArray[5];

if (month < 1 || month > 12)

{

return false;

}

if (day < 1 || day > 31)

{

return false;

}

if ((month==4 || month==6 || month==9 || month==11) && day==31)

{

return false;

}

if (month == 2)

{

var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));

if (day > 29 || (day==29 && !isleap))

{

return false;

}

}

return true;

}

</script>

All Comments

Leave a comment...

  • 1 Comments
    • Hello,

      >> but when the page is submitted from the javascript, the apex process does not run

      You are using the following to submit your page: doSubmit('Add Impact');

      That's setting the REQUEST value to 'Add Impact' (the name of the PL/SQL process?), which is not a predefined value of REQUEST. If your process is not specifically conditioned by this REQUEST value, I suspect it will be ignored. You should try one of the predefined REQUEST values (recognized by the APEX engine) like doSubmit('APPLY');, or specifically condition your process with this value of REQUEST.

      Also, I believe the doSubmit should be the last active statement in your JavaScript code. If you want to issue a success message, you should use the PL/SQL process property for that.

      Hope it helps,

      Arie.

      #1; Sat, 23 Feb 2008 19:44:00 GMT