Skip to main content
Inspiring
July 7, 2022
Answered

Error checking using multiple yes / No responses

  • July 7, 2022
  • 2 replies
  • 455 views

I am working on a form the user fills out to creat a document. Once the create document is pressed, the form will check to see if the user has forgotten to account for any equipment that may be required but forgotten to add. I am trying to use simple yes or no answers to allow the script to end so they can go back and make corrections if needed. The code works great if the response is triggered, not so great if the conditions are not met. Is there a way to simplify this so the program continues if the conditions are not met?

Here is the section I am having trouble with:

 

// Ensures that High-Pressure Pumps are assigned if required;

if ((p1480.value === 0)&&(p1800.value === 0)&&(p2200.value === 0)&&(p3600.value === 0)&&(c800.value === 0)&&(c3000.value === 0)){

var hppans = app.alert({cMsg:"No High-Pressure Pumps are assigned to this sulfide Job.\n\n" + "Please acknowledge this is correct.",nIcon:2,nType:2 });
}

// User Pressed Yes;
else if(hppans === 4){


// Ensures that H2S Analyzers are assigned if required;
if ((c1d1.value === 0)&&(c1d2.value === 0)&&(scan.value === 0)){

var h2sans = app.alert({cMsg:"No H2S Analyzers are assigned to this sulfide Job.\n\n" + "Please acknowledge this is correct.",nIcon:2,nType:2 });
}

// User Pressed Yes;
if(h2sans === 4){

// Ensures that OTIS Unit are assigned if required;
if (otis.value === 0){

var otisans = app.alert({cMsg:"No OTIS Units are assigned to this sulfide Job.\n\n" + "Please acknowledge this is correct.",nIcon:2,nType:2 });
}

// User Pressed Yes;
if(otisans === 4){


var nser1 = app.alert ({cMsg:"The Technical Package is about to be created.\n\n" + "Have you verified that all information entered is correct?",nIcon:2,nType:2 });

// User Pressed Yes;
if(nser1 === 4){

 

This topic has been closed for replies.
Correct answer try67

Your curly brackets are not set up correctly. Also, instead of nesting the code deeper and deeper you should use a function and just exit it if they user clicks No at any point. Like this:

 

function validateInput() {
	// add variable definitions here
	
	// Ensures that High-Pressure Pumps are assigned if required;
	if ((p1480.value === 0)&&(p1800.value === 0)&&(p2200.value === 0)&&(p3600.value === 0)&&(c800.value === 0)&&(c3000.value === 0)){
		if (app.alert({cMsg:"No High-Pressure Pumps are assigned to this sulfide Job.\n\n" + "Please acknowledge this is correct.",nIcon:2,nType:2 })!=4) return;
	}
	
	// Ensures that H2S Analyzers are assigned if required;
	if ((c1d1.value === 0)&&(c1d2.value === 0)&&(scan.value === 0)){
		if (app.alert({cMsg:"No H2S Analyzers are assigned to this sulfide Job.\n\n" + "Please acknowledge this is correct.",nIcon:2,nType:2 })!=4) return;
	}	
	
	// etc.
}

validateInput();

2 replies

DuquetteAuthor
Inspiring
July 15, 2022

Thank You try67 - works perfectly!

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 8, 2022

Your curly brackets are not set up correctly. Also, instead of nesting the code deeper and deeper you should use a function and just exit it if they user clicks No at any point. Like this:

 

function validateInput() {
	// add variable definitions here
	
	// Ensures that High-Pressure Pumps are assigned if required;
	if ((p1480.value === 0)&&(p1800.value === 0)&&(p2200.value === 0)&&(p3600.value === 0)&&(c800.value === 0)&&(c3000.value === 0)){
		if (app.alert({cMsg:"No High-Pressure Pumps are assigned to this sulfide Job.\n\n" + "Please acknowledge this is correct.",nIcon:2,nType:2 })!=4) return;
	}
	
	// Ensures that H2S Analyzers are assigned if required;
	if ((c1d1.value === 0)&&(c1d2.value === 0)&&(scan.value === 0)){
		if (app.alert({cMsg:"No H2S Analyzers are assigned to this sulfide Job.\n\n" + "Please acknowledge this is correct.",nIcon:2,nType:2 })!=4) return;
	}	
	
	// etc.
}

validateInput();