Ruby Code Exception

Hi Team,

I am getting
Ruby exception occurred: undefined method `length' for nil
error while using the following Ruby Code

ruby {
    code => '
      names = event.get("[message]").split(".")
      event.set("number_of_elements", event.get("[names]").length)
      event.set("[tp]", names)

message => "bob.alice.jessie.tommy"

Please help me to get this

I am trying to get length of the [names] array


This means that the value of [names] is null.

Do you have a field named names in your event?

What you probably want is the length of the variable names, you should try to use names.length, using event.get("[names]").length will try to get the length of the names field from your document.

1 Like

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