Skip to main content
Inspiring
September 13, 2023
Answered

Help with Custom Calculations

  • September 13, 2023
  • 1 reply
  • 3681 views

Hello,

 

I'm preparing a form that calculates a projects complexity based off of the project length and the number of utilities. The Project Length field will either be less than, greater than or equal to 1 mile and the No of UTs field would be a range of utilities. For example, a project with 7-10 utilities and a length of 1 mile or more would be a complexity level 7. I couldn't find a discussion where someone had the same problem.

This topic has been closed for replies.
Correct answer Badhawg66

This is not valid:

(this.getField("No of UTs").value >= 4 && <= 6)

You need to either use a variable, or repeat the full statement for each condition, like this:

(this.getField("No of UTs").value >= 4 && this.getField("No of UTs").value <= 6)


I wish I knew how to use variables but this script seems to work just fine. Thank you for your help!

 

if((this.getField("No of UTs").value == 1))
{
event.value = 1;
}
if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value <= 3))
{
event.value = 2;
}
if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value >= 3))
{
event.value = 3;
}
if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 4))
{
event.value = 4;
}

if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 5))
{
event.value = 4;
}

if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 6))
{
event.value = 4;
}
if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 4))
{
event.value = 5;
}

if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 5))
{
event.value = 5;

}
if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 6))
{
event.value = 5;
}
if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 7))
{
event.value = 6;

}

if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 8))
{
event.value = 6;
}

if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 9))
{
event.value = 6;
}

if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 10))
{
event.value = 6;
}

if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 7))

{
event.value = 7;
}

if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 8))

{
event.value = 7;
}

if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 9))

{
event.value = 7;
}

if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 10))

{
event.value = 7;
}

if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 11))
{
event.value = 8;
}

if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 12))
{
event.value = 8;
}

if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 13))
{
event.value = 8;
}

if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 14))
{
event.value = 8;
}

if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value = 15))
{
event.value = 8;
}

if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 11))
{
event.value = 9;
}

if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 12))
{
event.value = 9;
}

if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 13))
{
event.value = 9;
}

if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 14))
{
event.value = 9;
}

if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value = 15))
{
event.value = 9;
}


if((this.getField("No of UTs").value >= 15))
{
event.value = 10;
}
else
{
// do nothing
}

1 reply

try67
Community Expert
Community Expert
September 13, 2023

You need to better define the formula for this calculation...

> The Project Length field will either be less than, greater than or equal to 1 mile

So basically, any possible value...

> and the No of UTs field would be a range of utilities.

Not very descriptive...

> For example, a project with 7-10 utilities and a length of 1 mile or more would be a complexity level 7.

Why? What's the formula to arrive to that? Why not 10? Why not 8? Is it the product of the length by the number of utilities? What's the cut-off? A lot of info missing there.

Badhawg66Author
Inspiring
September 13, 2023

I apologize for being so vague. I'm trying to get rid of this cheat sheet I use. I'm hoping there's a way to make a script or multiple scripts that will help us figure out the complexity based off of the project length and number of utilities.

try67
Community Expert
Community Expert
November 27, 2023

Here is my script (It says I have syntax errors but I don't know what they are or how to fix them) If none of the conditions are true I want the Complexity field to stay blank. What am I doing wrong?

 

if(this.getField("No of UTs#1").value == 1)
{
event.value = 1;
}
if(this.getField("Proj Length#1").value < 1) && (this.getField("No of UTs#1").value <= 3)
{
event.value = 2;
}
if(this.getField("Proj Length#1").value > 1) && (this.getField("No of UTs#1").value >= 3)
{
event.value = 3;
}
if(this.getField("Proj Length#1").value < 1) && (this.getField("No of UTs#1").value >= 4 && <=6)
{
event.value = 4;
}
if(this.getField("Proj Length#1").value > 1) && (this.getField("No of UTs#1").value >= 4 && <=6)
{
event.value = 5;
}
if(this.getField("Proj Length#1").value < 1) && (this.getField("No of UTs#1").value >= 7 && <=10)
{
event.value = 6;
}
if(this.getField("Proj Length#1").value > 1) && (this.getField("No of UTs#1").value >= 7 && <=10)
{
event.value = 7;
}

if(this.getField("Proj Length#1").value < 1) && (this.getField("No of UTs#1").value >= 11 && <=15)
{
event.value = 8;
}
if(this.getField("Proj Length#1").value > 1) && (this.getField("No of UTs#1").value >= 11 && <=15)
{
event.value = 9;
}

if(this.getField("No of UTs#1").value >= 15)
{
event.value = 10;

}

else

{

// do nothing

}

 


Each condition after the if-statement has to be encapsulated in a set of parentheses.

So instead of this:

if (this.getField("Proj Length#1").value < 1) && (this.getField("No of UTs#1").value <= 3) {

You must use this:

if ((this.getField("Proj Length#1").value < 1) && (this.getField("No of UTs#1").value <= 3)) {

etc.