Else if condition not working

Hi all,

I'm trying to write a scripted field.
But I"m unable to execute else if condition as below:

if (doc.containsKey("report_card.grade") && !doc["report_card.grade"].empty) { 
if (doc["report_card.grade"].value == 5) { return "A"; } 
else if 
(doc["report_card.grade"].value == 4) { return "B"; }
else if 
(doc["report_card.grade"].value == 3) { return "C"; } 
else if 
(doc["report_card.grade"].value == 2) { return "D"; } 
else if 
(doc["report_card.grade"].value == 1) { return "E"; } 
else if 
(doc["report_card.grade"].value == 0) { return "F"; } 

else { return "-" ; } } 
else { return "-" ; }

I have tried condition with >= or <=, still it displays only 1 value(A or E)
I'm trying to figure out where i went wrong in code.
But unable to do so.

Any help please.

OK, so I came to know my field is a list.

report_card
{
  "name": "antiVirus",
  "grade": 1
},
{
  "name": "localFirewall",
  "grade": 1
},
{
  "name": "insecureListeningPorts",
  "grade": 5
},
{
  "name": "failedLogin",
  "grade": 1
},
{
  "name": "networkVulnerabilities",
  "grade": 5
},
{
  "name": "systemAging",
  "grade": 5
},
{
  "name": "supportedOS",
  "grade": 4
}

So I need to use a different Script for a list type field using a 'for loop' or have to get my fields seperately instead of a list

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.