# How to encode expression in Cumulocity AnalyticsBuilder?

**URL:** <https://community.cumulocity.com/t/how-to-encode-expression-in-cumulocity-analyticsbuilder/3138>\
**Category:** Forum\
**Tags:** Streaming-Analytics-Apama, cumulocity\
**Created:** [July 12, 2022, 2:25pm UTC](https://community.cumulocity.com/t/how-to-encode-expression-in-cumulocity-analyticsbuilder/3138 "2022-07-12T14:25:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christof\_Strack](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/christof_strack/32/30066_2.png) [@Christof\_Strack](https://community.cumulocity.com/u/Christof_Strack)\
**Post date:** [July 12, 2022, 2:25pm UTC](https://community.cumulocity.com/t/how-to-encode-expression-in-cumulocity-analyticsbuilder/3138/1 "2022-07-12T14:25:49Z")

</div>

Hi,

I want to build an AnalyticsBuilder model for extracting the payload of an event.  
For this I parse the string which contains a sequence of integers: “[68,70,71,49,50,0,0,0,27,91,48]”.  
In pure EPL I can use `sequence<integer>.parse("[80,90]")[0]`.  
How do I have to encode this expression in the AnalyticsBuilder?

Regards Christof

---

<div class="post-metadata">

**Author:** ![anon47495121](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@anon47495121](https://community.cumulocity.com/u/anon47495121)\
**Post date:** [July 14, 2022, 12:07pm UTC](https://community.cumulocity.com/t/how-to-encode-expression-in-cumulocity-analyticsbuilder/3138/2 "2022-07-14T12:07:43Z")

</div>

Hi,  
It is a little vague as to where the string is coming from like whether it is the stringified version of a json sequence or a literal string. More details on it will be helpful. We can do more with the json if we know its structure.

Thanks,  
Sasmita

---

<div class="post-metadata">

**Author:** ![anon47495121](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@anon47495121](https://community.cumulocity.com/u/anon47495121)\
**Post date:** [July 18, 2022, 8:11am UTC](https://community.cumulocity.com/t/how-to-encode-expression-in-cumulocity-analyticsbuilder/3138/3 "2022-07-18T08:11:01Z")

</div>

HI @Christof_Strack , is it resolved, did you find any solution for it or need any assistance?

Thanks,  
Sasmita

---

<div class="post-metadata">

**Author:** ![Christof\_Strack](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/christof_strack/32/30066_2.png) [@Christof\_Strack](https://community.cumulocity.com/u/Christof_Strack)\
**Post date:** [July 18, 2022, 12:32pm UTC](https://community.cumulocity.com/t/how-to-encode-expression-in-cumulocity-analyticsbuilder/3138/4 "2022-07-18T12:32:36Z")

</div>

Hi @anon47495121,  
no, I still look for a solution.  
My event looks as follows:

```auto
{
    "source": {
        "id": "4711"
    },
    "type": "c8y_EK_0_0",
    "time": "SOME_TIMESTAMP",
    "text": "EK belegt",
    "resourcePath": "/19/0/0",
    "deviceName": "1223334444",
    "objectResourcePath_/19/0/0": {},
    "resourceValue": "[180, 60, 40, 30]"
}

```

… and I want to parse resourceValue, i.e. get 180 as an number.

Regards Christof

---

<div class="post-metadata">

**Author:** ![anon47495121](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@anon47495121](https://community.cumulocity.com/u/anon47495121)\
**Post date:** [July 19, 2022, 9:05am UTC](https://community.cumulocity.com/t/how-to-encode-expression-in-cumulocity-analyticsbuilder/3138/5 "2022-07-19T09:05:21Z")

</div>

Hi @Christof_Strack ,

After you extract the value of “resourceValue” (by using Extract Property block), to extract elements of sequence you need to create a custom block.

If you want to achieve it using standard blocks, you can use Expression block but it’s difficult parsing and extracting elements as there is no decent way to achieve it. Expression block does not support sequence and squqare bracket ([])operators. Easiest would be to write a custom block.

If you still want to extract index values using Expression block, it is complicated(and ugly). You can try this way.  
Ex:

```auto
For index 0: **input1.substring(1.floor(), input1.findFrom(",", 0.floor()))**

For index 1: **input1.substring(input1.findFrom(",", 0.floor())+1.floor(), input1.findFrom(",", input1.findFrom(",", 0.floor())+1.floor()))**

For index 2: **input1.substring(input1.findFrom(",", input1.findFrom(",", 0.floor())+1.floor())+1.floor(), input1.findFrom(",", input1.findFrom(",", input1.findFrom(",",0.floor())+1.floor())+1.floor()))**

```

substring and findFrom takes integer parameter(see [string](https://documentation.softwareag.com/apama/v10-11/apama10-11/ApamaDoc/string.html)). But in analytics builder, numeric literals are treated as float values so we need to call .floor() or other comparable methods to convert them to int before passing them to findFrom or substring action.

It becomes complicated , if the sequence length increases and if resourceValue is empty.

So, suggest to use custom block instead of expression block.

Best Regards,  
Sasmita

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [October 17, 2022, 9:06am UTC](https://community.cumulocity.com/t/how-to-encode-expression-in-cumulocity-analyticsbuilder/3138/6 "2022-10-17T09:06:10Z")

</div>

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