Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I still don't understand how these values are specified by the user. Are you using a drop-down?
Can you share the actual file?
Copy link to clipboard
Copied
No but you could use a drop down for the No of UTs field. Here is the file I'm working with.
Copy link to clipboard
Copied
try67,
What am I doing wrong? I get ReferenceError: invalid assignment left-hand side 1: at line 2. Ln 12, Col 2
Here is the script I used...
if((this.getField("No of UTs#1").value == ('Proj Length' = 1))
{
event.value = 1;
}
if((this.getField("Proj Length#1").value == ('Proj Length' < 1)) && (this.getField("No of UTs#1").value == ("No of UTs#1" ≤ 3"))
{
event.value = 2;
}
Copy link to clipboard
Copied
Following is wrong:
'Proj Length' = 1
You can't assign a value to a string.
Copy link to clipboard
Copied
There are a lot of issues with your code. Bernd pointed out the main one, but this is also wrong:
if((this.getField("Proj Length#1").value == ('Proj Length' < 1))
You're combining multiple comparisons in a way that doesn't make sense.
Also, "≤ " is not a valid operator in JS.
Copy link to clipboard
Copied
I think I understand what you guys are trying to say. Does this look better?
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;
}
Copy link to clipboard
Copied
Yes, much better, although you need to consider what will happen if neither condition is true.
Currently, whatever value the field had before will stay in place. Not sure that's what you want to happen...
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
So like this? It says line 14 has an invalid XML name (I deleted the # by the field names but that didn't fix problem)
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 && <=6))
{
event.value = 4;
}
if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value >= 4 && <=6))
{
event.value = 5;
}
if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value >= 7 && <=10))
{
event.value = 6;
}
if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value >= 7 && <=10))
{
event.value = 7;
}
if((this.getField("Proj Length").value < 1) && (this.getField("No of UTs").value >= 11 && <=15))
{
event.value = 8;
}
if((this.getField("Proj Length").value > 1) && (this.getField("No of UTs").value >= 11 && <=15))
{
event.value = 9;
}
if((this.getField("No of UTs").value >= 15))
{
event.value = 10;
}
else
{
// do nothing
}
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
It's quite simple. You define them once at the start of your code with the values of the fields, and then use them directly instead of accessing the fields each time. Something like this:
var numUTs = Number(this.getField("No of UTs").value);
var projLength = Number(this.getField("Proj Length").value);
if(numUTs == 1)
{
event.value = 1;
}
if((projLength < 1) && (numUTs <= 3))
etc.

