# ES watcher Transform: formatting the script source

**URL:** <https://discuss.elastic.co/t/es-watcher-transform-formatting-the-script-source/219660>\
**Category:** Elasticsearch\
**Created:** [February 17, 2020, 5:03pm UTC](https://discuss.elastic.co/t/es-watcher-transform-formatting-the-script-source/219660 "2020-02-17T17:03:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdelhedi\_yassine](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@abdelhedi\_yassine](https://discuss.elastic.co/u/abdelhedi_yassine)\
**Post date:** [February 17, 2020, 5:03pm UTC](https://discuss.elastic.co/t/es-watcher-transform-formatting-the-script-source/219660/1 "2020-02-17T17:03:39Z")

</div>

Hi team,

I'm really getting a hard time working with transform scripts cause it's only allowing me to write on 1 line:

example:

```
"transform": {
"script": {
"source": " String k; int i; int s; int a; float sar; for(i=0;i<ctx.payload.aggregations.direction.buckets.size();i++){if(ctx.payload.aggregations.direction.buckets[i].key == 'submitted'){s=ctx.payload.aggregations.direction.buckets[i].doc_count;} else {a=ctx.payload.aggregations.direction.buckets[i].doc_count;}} sar=a*100/s;DecimalFormat df = new DecimalFormat('###'); k=df.format(sar); List Result = ['Attempted', a, 'Submitted', s, k]; return Result;",
"lang": "painless"
}
}

```

=\> question : is it possible to have a Carriage return on the script to have something like the following:

```
"transform": {
"script": {
"source": "
String k;
int i;
int s;
int a;
float sar;
for(i=0;i<ctx.payload.aggregations.direction.buckets.size();i++)
{
if(ctx.payload.aggregations.direction.buckets[i].key == 'submitted')
{
s=ctx.payload.aggregations.direction.buckets[i].doc_count;
}
else
{
a=ctx.payload.aggregations.direction.buckets[i].doc_count;
}
}
sar=a*100/s;
DecimalFormat df = new DecimalFormat('###');
k=df.format(sar);
List Result = ['Attempted', a, 'Submitted', s, k];
return Result;",
"lang": "painless"
}
}

```

I put """ surrounding the source block.. but saying "Invalid json".

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/2/92f0abd8c83784e0b607408c18d91fc3fd20fbeb.png)

is there a way to do it or put the script in a file and call it??

Thanks

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 18, 2020, 10:13am UTC](https://discuss.elastic.co/t/es-watcher-transform-formatting-the-script-source/219660/2 "2020-02-18T10:13:03Z")

</div>

The usage of triple ticks within kibana looks correct at a first glance. Is this Kibana and if so, which version of the stack are you using?

--Alex

---

<div class="post-metadata">

**Author:** ![abdelhedi\_yassine](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@abdelhedi\_yassine](https://discuss.elastic.co/u/abdelhedi_yassine)\
**Post date:** [February 18, 2020, 10:25am UTC](https://discuss.elastic.co/t/es-watcher-transform-formatting-the-script-source/219660/3 "2020-02-18T10:25:17Z")

</div>

Yes Alex, this is Kibana, v 6.8.0

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 18, 2020, 10:29am UTC](https://discuss.elastic.co/t/es-watcher-transform-formatting-the-script-source/219660/4 "2020-02-18T10:29:23Z")

</div>

can you share the full watch as text, so one can try and copy paste that into a dev-tools console?

---

<div class="post-metadata">

**Author:** ![abdelhedi\_yassine](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@abdelhedi\_yassine](https://discuss.elastic.co/u/abdelhedi_yassine)\
**Post date:** [February 18, 2020, 10:50am UTC](https://discuss.elastic.co/t/es-watcher-transform-formatting-the-script-source/219660/5 "2020-02-18T10:50:22Z")

</div>

Hi Alex,

thanks for the hint. Actually I was using the _ **advanced watcher** _ console and it wasn't working from there.  
Now I put my watch in **dev-tools** console and from there I was able to execute it using the triple ticks.

thanks for you support

---

<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 17, 2020, 10:59am UTC](https://discuss.elastic.co/t/es-watcher-transform-formatting-the-script-source/219660/6 "2020-03-17T10:59:24Z")

</div>

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