# GREL function previews ok, then fails

**URL:** <https://forum.openrefine.org/t/grel-function-previews-ok-then-fails/733>\
**Category:** Data cleaning and transformations\
**Created:** [April 26, 2023, 5:32pm UTC](https://forum.openrefine.org/t/grel-function-previews-ok-then-fails/733 "2023-04-26T17:32:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhammock](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/jhammock/32/470_2.png) [@jhammock](https://forum.openrefine.org/u/jhammock)\
**Post date:** [April 26, 2023, 5:32pm UTC](https://forum.openrefine.org/t/grel-function-previews-ok-then-fails/733/1 "2023-04-26T17:32:05Z")

</div>

Hello! I’m using Version 3.4.1, and trying to add a column based on an existing column. (The original contains a list, and I’m trying to select the last item.) The preview shows the result I’m expecting, but when the column is created, the cells are empty. My (possibly inelegant) grel is:

value.split(", “).slice(length(value.split(”, "))-1)

Any ideas how I can get the actual result to resemble the preview result?

Thanks!

Jen

P.S. If I ask it to store error:

“Object [] value not storable”

 ![Screen Shot 2023-04-26 at 1.30.57 PM](https://europe1.discourse-cdn.com/flex017/uploads/openrefine/original/1X/ce9b759e7f59ce4b91f17ee5fbc15d764407c0d9.jpeg)

---

<div class="post-metadata">

**Author:** ![tfmorris](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/tfmorris/32/17_2.png) [@tfmorris](https://forum.openrefine.org/u/tfmorris)\
**Post date:** [April 26, 2023, 6:39pm UTC](https://forum.openrefine.org/t/grel-function-previews-ok-then-fails/733/2 "2023-04-26T18:39:38Z")

</div>

> Hello! I’m using Version 3.4.1, and trying to add a column based on an existing column. (The original contains a list, and I’m trying to select the last item.) The preview shows the result I’m expecting, but when the column is created, the cells are empty. My (possibly inelegant) grel is:
> 
> value.split(", “).slice(length(value.split(”, "))-1)
> 
> Any ideas how I can get the actual result to resemble the preview result?

Your expression creates an array which can't be stored in a cell (it can only be used for intermediary values). You can simplify things by using negative indexes to index relative to the end of the array. Try the following:

value.split(", “)[-1]

Tom

---

<div class="post-metadata">

**Author:** ![jhammock](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/jhammock/32/470_2.png) [@jhammock](https://forum.openrefine.org/u/jhammock)\
**Post date:** [April 26, 2023, 8:17pm UTC](https://forum.openrefine.org/t/grel-function-previews-ok-then-fails/733/3 "2023-04-26T20:17:22Z")

</div>

Ah, I understand. Thanks very much! I have a lot to learn about the distinctions among different kinds of objects.

---

<div class="post-metadata">

**Author:** ![thadguidry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/thadguidry/32/653_2.png) [@thadguidry](https://forum.openrefine.org/u/thadguidry)\
**Post date:** [April 27, 2023, 12:38am UTC](https://forum.openrefine.org/t/grel-function-previews-ok-then-fails/733/4 "2023-04-27T00:38:25Z")

</div>

> `Object[] value not storable`

@jhammock Yeah, that's not helpful at all to you is it? What if we changed the output to say something like the below Stored Error?

@tfmorris We could do better, I tried to improve it, but cannot get this code to work in ExpressionUtils.java to work:

```java
    static public Serializable wrapStorable(Object v) {
        if (v instanceof ArrayNode) {
            return ((ArrayNode) v).toString();
        } else if (v instanceof ObjectNode) {
            return ((ObjectNode) v).toString();
        } else if (v.getClass().isArray()) {
            return new EvalError(
                  "Stored Error: Your expression created an Array."
                + "Only Number, String, Boolean, OffsetDateTime can be stored in a cell."
                + "HINT: try appending to your expression: .join(',') to store as a String.");
        } else {
            return isStorable(v) ? (Serializable) v : new EvalError(v.getClass().getSimpleName() + " value not storable");
        }
    }

```

---

<div class="post-metadata">

**Author:** ![jhammock](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/jhammock/32/470_2.png) [@jhammock](https://forum.openrefine.org/u/jhammock)\
**Post date:** [April 27, 2023, 1:01am UTC](https://forum.openrefine.org/t/grel-function-previews-ok-then-fails/733/5 "2023-04-27T01:01:19Z")

</div>

@thadguidry I dig the detailed error message. Given that HINT, I might not have learned the streamlined solution @tfmorris provided, but it did work for my case, and I can see it would generalize for other people finishing with an array.
