Runtime field component mapping with IF in script fails to parse due to compile error

I'm trying to create a mapping based on a value. However, whatever I try to save the component template, I'm shown the following error:

:warning: Unable to create component template
Failed to parse mapping: compile error

The runtime field component mapping I'm trying to create is:

if (!doc['policy_evaluated.spf'].value.equals('None') && 
  doc['policy_evaluated.spf'].value.toLowerCase().equals("pass"))
{
  return true
} else {
  return false
}

In examples of scripts with if statement I see them wrapped in """, but with or without, I get the same error.

One must use emit not return... Correct script:

if (!doc['policy_evaluated.spf'].value.equals('None') &&
  doc['policy_evaluated.spf'].value.toLowerCase().equals("pass"))
{
  emit(true)
} else {
  emit(false)
}

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