# Help with scripted fields

**URL:** <https://discuss.elastic.co/t/help-with-scripted-fields/152415>\
**Category:** Kibana\
**Created:** [October 15, 2018, 2:40am UTC](https://discuss.elastic.co/t/help-with-scripted-fields/152415 "2018-10-15T02:40:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremiguel](https://avatars.discourse-cdn.com/v4/letter/j/6bbea6/32.png) [@jeremiguel](https://discuss.elastic.co/u/jeremiguel)\
**Post date:** [October 15, 2018, 2:40am UTC](https://discuss.elastic.co/t/help-with-scripted-fields/152415/1 "2018-10-15T02:40:05Z")

</div>

I'm a complete beginner with Kibana and its my first time creating a scripted field. I'm creating a script to retrieve the transaction id's of dropped transactions from all my transaction logs.

Below is the script which contains an error that I don't understand. It'd be great if someone could explain it to me and provide me with tips for a fix.

\</\>  
string current = "abc";  
for (def log1 : doc['invoice\_id'].values {  
if (log1 != current) {  
log1 = current;  
for (def log2 : doc['invoice\_id'].values) {  
if (log2 == current) {  
if (doc['log\_type'].values.contains("MER\_REQUEST")) {  
if (doc['log\_type'].values.contains("MER\_RESPONSE")) {  
}  
else {  
return current;  
}  
}  
}  
}  
}  
}  
\</\>

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 15, 2018, 6:03am UTC](https://discuss.elastic.co/t/help-with-scripted-fields/152415/2 "2018-10-15T06:03:07Z")

</div>

I am not sure I understand what you are trying to achieve. Be aware that the scripted field runs in the context of a single document, so you can not compare values from different documents (if that is what you are trying to do).

---

<div class="post-metadata">

**Author:** ![jeremiguel](https://avatars.discourse-cdn.com/v4/letter/j/6bbea6/32.png) [@jeremiguel](https://discuss.elastic.co/u/jeremiguel)\
**Post date:** [October 15, 2018, 6:54am UTC](https://discuss.elastic.co/t/help-with-scripted-fields/152415/3 "2018-10-15T06:54:06Z")

</div>

Oh, I was actually trying to compare values from different logs. Thanks for the help, I'll try to find a workaround. Also, sorry that my question wasn't clear.

---

<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:** [November 12, 2018, 6:54am UTC](https://discuss.elastic.co/t/help-with-scripted-fields/152415/4 "2018-11-12T06:54:07Z")

</div>

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