# How can I pass field reference in ruby filter while constructing a big string

**URL:** <https://discuss.elastic.co/t/how-can-i-pass-field-reference-in-ruby-filter-while-constructing-a-big-string/279419>\
**Category:** Logstash\
**Created:** [July 22, 2021, 6:37pm UTC](https://discuss.elastic.co/t/how-can-i-pass-field-reference-in-ruby-filter-while-constructing-a-big-string/279419 "2021-07-22T18:37:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankitdevnalkar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankitdevnalkar/32/46158_2.png) [@ankitdevnalkar](https://discuss.elastic.co/u/ankitdevnalkar)\
**Post date:** [July 22, 2021, 6:37pm UTC](https://discuss.elastic.co/t/how-can-i-pass-field-reference-in-ruby-filter-while-constructing-a-big-string/279419/1 "2021-07-22T18:37:22Z")

</div>

I would want to construct a sentence having multiple dynamic values, for example

```auto
ruby 
{
    code => '
    my_object = 
    {
    "reason" => "I received event.get("baseValueUnitAmount") event.get("currency") having difference of event.get("[differenceUnitAmount]") compare to previous transaction."
    }
    '
}

```

Expected output:  
`I received 25000 INR having difference of 5000 compare to previous transaction`

---

<div class="post-metadata">

**Author:** ![ankitdevnalkar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankitdevnalkar/32/46158_2.png) [@ankitdevnalkar](https://discuss.elastic.co/u/ankitdevnalkar)\
**Post date:** [July 22, 2021, 7:16pm UTC](https://discuss.elastic.co/t/how-can-i-pass-field-reference-in-ruby-filter-while-constructing-a-big-string/279419/2 "2021-07-22T19:16:10Z")

</div>

This has been resolved...

one can assign event values to a variable and then pass it with `#{value}` inside string.

For example

```auto
ruby 
{
    code => '
    a = event.get("baseValueUnitAmount")
    b = event.get("currency")
    c = event.get("[differenceUnitAmount]")
    my_object = 
    {
    "reason" => "I received #{a} #{b} having difference of #{c} compare to previous transaction."
    }
    '
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 19, 2021, 7:16pm UTC](https://discuss.elastic.co/t/how-can-i-pass-field-reference-in-ruby-filter-while-constructing-a-big-string/279419/3 "2021-08-19T19:16:38Z")

</div>

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