# Scripted Field in Data Table

**URL:** <https://discuss.elastic.co/t/scripted-field-in-data-table/296871>\
**Category:** Kibana\
**Created:** [February 10, 2022, 4:21pm UTC](https://discuss.elastic.co/t/scripted-field-in-data-table/296871 "2022-02-10T16:21:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stemons](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stemons/32/84571_2.png) [@stemons](https://discuss.elastic.co/u/stemons)\
**Post date:** [February 10, 2022, 4:21pm UTC](https://discuss.elastic.co/t/scripted-field-in-data-table/296871/1 "2022-02-10T16:21:09Z")

</div>

Hello, I'm working with data tables in kibana and would like to create an additional column from a script. The following script is working

```auto
{ "script" : 
    "if (doc['cpu.used.pct'].value > 100) { return 1 }"
}

```

But I would like to create a new field of type string. The following script is not working and returns:

class\_cast\_exception: class java.lang.String cannot be cast to class java.lang.Number (java.lang.String and java.lang.Number are in module java.base of loader 'bootstrap')

```auto
{ "script" : 
    "if (doc['cpu.used.pct'].value > 100) { return \"CRITICAL\" }"
}

```

Is there a way to achieve the result?  
Thanks

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [February 11, 2022, 4:04am UTC](https://discuss.elastic.co/t/scripted-field-in-data-table/296871/2 "2022-02-11T04:04:48Z")

</div>

> [@stemons](#):
>
> class\_cast\_exception: class java.lang.String cannot be cast to class java.lang.Number (java.lang.String and java.lang.Number are in module java.base of loader 'bootstrap')

The error seems caused by that you tried to insert string value to numerical field. You have to direct to text field if you want to return string data.

---

<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:** [March 11, 2022, 4:05am UTC](https://discuss.elastic.co/t/scripted-field-in-data-table/296871/3 "2022-03-11T04:05:09Z")

</div>

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