# Analytics builder text replace with measurement value

**URL:** <https://community.cumulocity.com/t/analytics-builder-text-replace-with-measurement-value/5556>\
**Category:** Forum\
**Tags:** analytics-builder, cumulocity\
**Created:** [January 13, 2022, 7:09pm UTC](https://community.cumulocity.com/t/analytics-builder-text-replace-with-measurement-value/5556 "2022-01-13T19:09:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![johannesmichael](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@johannesmichael](https://community.cumulocity.com/u/johannesmichael)\
**Post date:** [January 13, 2022, 7:09pm UTC](https://community.cumulocity.com/t/analytics-builder-text-replace-with-measurement-value/5556/1 "2022-01-13T19:09:53Z")

</div>

Hi  
I am on eu-latest.

I created a smart rule, that raises an alarm when a threshold is exceeded.  
Then I want to send out an email, with the current measurement in the text.  
How to achieve this?

Not working:

_New #{severity} alarm has been received from #{source.name} with value #{source.value}. Alarm text is: “#{text}”._  
_New #{severity} alarm has been received from #{source.name} with value #{value}. Alarm text is: “#{text}”._

I also tried it with the analytics builder with text replace, but all things I tried did not resolve to the value:

Not working:  
_Value:: #{c8y\_Humidity.value}. At #{time} → time works fine_  
_Value:: #{c8y\_Humidity.C.value}. At #{time}_  
_Value:: #{source.value}. At #{time}_

Thanks for your help.  
Johannes

---

<div class="post-metadata">

**Author:** ![Christian\_Guether1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/christian_guether1/32/14848_2.png) [@Christian\_Guether1](https://community.cumulocity.com/u/Christian_Guether1)\
**Post date:** [January 14, 2022, 7:39am UTC](https://community.cumulocity.com/t/analytics-builder-text-replace-with-measurement-value/5556/2 "2022-01-14T07:39:05Z")

</div>

Hi Johannes,

I can’t comment on the Analytics Builder, but maybe the behavior is the same as for Smart Rules. Smart Rules have common [variables and variables](https://cumulocity.com/guides/users-guide/cockpit/#smart-rule-variables), which are based on the context of the Smart Rule A Smart Rules always has a context, which is defined by the trigger of the Smart Rule. In your case, I assume you are using the `On alarm send email` rule. The trigger for this rule is the alarm, which means you only have access to fields and properties of the alarm. For alarms this would mean: `status`, `severity` and `count` (and of course all the common properties). This means you can’t access any properties from a measurement as it isn’t available in this particular context as the rule is only about an alarm being created and how you want to react to this event.

What you could do, is to modify the alarm text for your first threshold accordingly and have all necessary information of the measurement inside the alarm text. In your second rule you can access the alarm text property and display it in the email.

Best regards  
Christian

---

<div class="post-metadata">

**Author:** ![johannesmichael](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@johannesmichael](https://community.cumulocity.com/u/johannesmichael)\
**Post date:** [January 19, 2022, 11:49am UTC](https://community.cumulocity.com/t/analytics-builder-text-replace-with-measurement-value/5556/3 "2022-01-19T11:49:11Z")

</div>

Hi Christian,

sounds reasonable for Smart Rules, since the email is triggered from an alarm. But in analytics builder it is the measurement, that is going to be processed.

 ![grafik](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/4/5/450b5a6af04a8c44e8cdc0ebdf061876d4972640.png)

Best regards  
Johannes

---

<div class="post-metadata">

**Author:** ![Harald\_Meyer](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/harald_meyer/32/1959_2.png) [@Harald\_Meyer](https://community.cumulocity.com/u/Harald_Meyer)\
**Post date:** [January 19, 2022, 12:55pm UTC](https://community.cumulocity.com/t/analytics-builder-text-replace-with-measurement-value/5556/4 "2022-01-19T12:55:59Z")

</div>

Hi Johannes,

the problem is that the value of a measurement is not a property that can be extracted for text substitution but is the actual “thing” that is being transported. That’s why you observe that it works for the time.

The easiest solution would be to use the Set Properties block to store the measurement value in a property (e.g. “value”):

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/a/e/ae1d677709689c7534fd8786eb655c5a3e18c2e6.png)

Alternatively, you could also use the Expression block and perform String concatenation. Just remember to convert the value to a string first.

Best regards,  
Harald

---

<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:** [April 19, 2022, 12:56pm UTC](https://community.cumulocity.com/t/analytics-builder-text-replace-with-measurement-value/5556/5 "2022-04-19T12:56:04Z")

</div>

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