# Scripted Field Referencing another Scripted Field (Array)

**URL:** <https://discuss.elastic.co/t/scripted-field-referencing-another-scripted-field-array/99065>\
**Category:** Kibana\
**Created:** [August 31, 2017, 10:29pm UTC](https://discuss.elastic.co/t/scripted-field-referencing-another-scripted-field-array/99065 "2017-08-31T22:29:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert.S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robert.s/32/22039_2.png) [@Robert.S](https://discuss.elastic.co/u/Robert.S)\
**Post date:** [August 31, 2017, 10:29pm UTC](https://discuss.elastic.co/t/scripted-field-referencing-another-scripted-field-array/99065/1 "2017-08-31T22:29:05Z")

</div>

I am new at this, and not sure if it is doable. I am trying to set an array, then validate a field value (whether its exists in my array) all in one, or 2 separate scripted field.  
here is what I have, and what I am trying to do:

I have this and it works, but it feels redundant:  
sc-test  
if (  
doc['somefield.keyword'].value =~ /valueA/ ||  
doc['somefield.keyword'].value =~ /valueB/ ||  
doc['somefield.keyword'].value =~ /valueC/  
) {  
return "invalid PN"  
} else {  
return "valid PN"  
}

This is what I am looking to achieve:  
sc-list  
“ValueA,ValueB,ValueC”

sc-test  
if (  
doc['somefield.keyword'].value =~ doc['sc-list'].value  
) {  
return "invalid"  
} else {  
return "valid"  
}

or plugin the array on the same sc-test:

list = [ValueA,ValueB,ValueC]

if (  
doc['somefield.keyword'].value =~ list  
) {  
return "invalid"  
} else {  
return "valid"  
}

ERROR: Courier Fetch: 5 of 5 shards failed.

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [September 1, 2017, 7:10pm UTC](https://discuss.elastic.co/t/scripted-field-referencing-another-scripted-field-array/99065/2 "2017-09-01T19:10:12Z")

</div>

Unfortunately, it's currently not possible to reference one scripted field from another scripted field. If you'd like to see this, feel free to add an enhancement request on [Github](https://github.com/elastic/kibana).

---

<div class="post-metadata">

**Author:** ![Robert.S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robert.s/32/22039_2.png) [@Robert.S](https://discuss.elastic.co/u/Robert.S)\
**Post date:** [September 1, 2017, 9:25pm UTC](https://discuss.elastic.co/t/scripted-field-referencing-another-scripted-field-array/99065/3 "2017-09-01T21:25:51Z")

</div>

How can I define an array in the same scripted field, then do the validation against it?

---

<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:** [September 29, 2017, 9:26pm UTC](https://discuss.elastic.co/t/scripted-field-referencing-another-scripted-field-array/99065/4 "2017-09-29T21:26:05Z")

</div>

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