Hi -
I am still new to Arcade and need some help identifying what is wrong with my below expression. I have 4 questions (see image 1). Question 1 and 4 are answered in all cases. Question 2 and 3 are answered dependent upon another question indicating whether the project is an engineered or natural solution. If they answer Engineered, then they answer Question 2, if they answer Natural, they answer question 3. There is logic that makes the questions editable depending upon the initial response. The response to each question receives a score of 0, 10 or 20. We then give bonus points (Highest Possible Score question in image) based upon how many questions received 20 points using the below logic (image 2). My code does not return a number if any question=20, if they are all < 20 it correctly returns 0. Can anyone tell me what I am doing wrong?
Solved! Go to Solution.
@JoshuaSharp-Heward Thanks for your assistance on this - I really appreciate it. Knowing that you could get it to run, I started tracing back my steps and finally found the root cause. The Score fields are all short integers, but are calculated based upon select one questions. In those calculation scripts I had my numbers in single quotes which was causing the problem.
if ($feature.PR_RESF1=='1. RSS asset(s) BRE meet ALR'){
return '0';
I removed the single quotes, and the script is now working as expected :-). Being new to Arcade, I have to say I do not know when to use double quotes, single quotes or no quotes. It is often trial by error, but in this case the calculations for the score fields were running as expected and returning the correct values, so I did not know the single quotes were problematic.
Thanks again!
Hi,
I've gone for a slightly different approach to the problem as I think with that many if/else if clauses it can be tricky to work out what's going on.
var RESF1Score = $feature.PR_RESF1_SCORE
var RESF2Score = $feature.PR_RESF2ENG_SCORE + $feature.PR_RESF2NAT_SCORE
var RESF3Score = $feature.PR_RESF3_SCORE
function isTwenty(i) { return i == 20 }
var num20s = Count(Filter([RESF1Score, RESF2Score, RESF3Score], isTwenty)
When(num20s==3,20,num20s==2, 10, num20s==1, 5, 0)
To summarise what this is doing:
Hope this works for you! Seemed to be working fine in the Arcade playground for me.
Cheers,
Josh
Hi @JoshuaSharp-Heward -
Sorry for the slow reply, I am just getting back to this after getting pulled away on another project. I need to get the default values updated in my layer, and then I will see if this works.
Many thanks!
Leila
Hi Leila,
No worries, let me know how you get on 🙂
Josh
@JoshuaSharp-Heward I was able to test your code today, and it too only returns 0 for some reason. I also tried a hybrid script posted below with the same result. It seems like all of these should work - I feel like I am missing something really obvious. I cleared the entire "Highest" field to Null to make sure there wasn't lingering data in there and that the scripts were actually calculating, and they are, just to 0 always. The score fields are all short integers.
Thanks!
Leila
Hybrid script
Hi Laila,
Is the "Highest Possible Score" an integer field as well? I realised my script was missing a close bracket, although I assume you fixed that to get it to run! To clarify are you setting this up in the Forms tab in a web map? I've managed to replicate it and get it to run perfectly using this code:
var RESF1Score = $feature.RESF1
var RESF2Score = $feature.RESF2a + $feature.RESF2b
var RESF3Score = $feature.RESF3
function isTwenty(i) { return i == 20 }
var num20s = Count(Filter([RESF1Score, RESF2Score, RESF3Score], isTwenty))
When(num20s==3,20,num20s==2, 10, num20s==1, 5, 0)
So I feel confident that the code I've written works and is a bit easier to understand!
It might be worth putting a very simple calculation like
return 50
to see whether the calculation is even running at all? Could you post a screenshot of the questions in the form builder as well?
@JoshuaSharp-Heward Thanks for your assistance on this - I really appreciate it. Knowing that you could get it to run, I started tracing back my steps and finally found the root cause. The Score fields are all short integers, but are calculated based upon select one questions. In those calculation scripts I had my numbers in single quotes which was causing the problem.
if ($feature.PR_RESF1=='1. RSS asset(s) BRE meet ALR'){
return '0';
I removed the single quotes, and the script is now working as expected :-). Being new to Arcade, I have to say I do not know when to use double quotes, single quotes or no quotes. It is often trial by error, but in this case the calculations for the score fields were running as expected and returning the correct values, so I did not know the single quotes were problematic.
Thanks again!
No worries 🙂 I'm glad I could help out and that you managed to solve it in the end!