I am new to this and i am trying to put a simple if statement into a field based on the value of another field.
Can someone help me correct the below?
var score =this.getfield("PriorityScore").value;
If ((score <5))event.value="Declined";
If ((score >5)&&(score <=9))event.value="Low";
If ((score >10)&&(score <=17))event.value="Medium";
If ((score >18))event.value="High";
Else event.value= "error";
Use if, not If
Use else, not Else
Also, you might want to structure these statements as an if block. In this case, it's for efficiency, but it's also a good general practice to keep related condionals together so they don't walk on each other.
var score =this.getfield("PriorityScore").value; if (score <5)event.value="Declined"; else if ((score >5)&&(score <=9))event.value="Low"; else if ((score >10)&&(score <=17))event.value="Medium"; else if (score >18)event.value="High"; else event.value= "error";
In addition to the correct comments above, your code has various "blind spots", such as 5, 10 and 18, which will result in "error"...
Thank you for your help. I have pasted this into the calculate property of the field(below). But it isn't triggering the calculation. do i need to put it somewhere else?
Change getfield to getField
Good Catch!! The problems are always in the small details.
KMAS73, I see this consitently on the forum, i.e., the immediate assumption that if code is not working, then some specific issue such as "it isn't triggering the calculation" is the problem. It is generally a prudent and wise practice to reserver judgement until you've actually debugged the issue. The first step, as pointed out by Try67, is to check the console window. I would go a step farther and say you should test your code in the console first, before applying it to a field script.
Post the new version of your full code, as text, not a screenshot, and check the JS Console for errors after you change the value of any field in the file.