# AlarmNotification - How to parse expressions in a property

**URL:** <https://forum.inductiveautomation.com/t/alarmnotification-how-to-parse-expressions-in-a-property/7655>\
**Category:** Module Development\
**Created:** [December 2, 2013, 9:21pm UTC](https://forum.inductiveautomation.com/t/alarmnotification-how-to-parse-expressions-in-a-property/7655 "2013-12-02T21:21:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [December 2, 2013, 9:21pm UTC](https://forum.inductiveautomation.com/t/alarmnotification-how-to-parse-expressions-in-a-property/7655/1 "2013-12-02T21:21:34Z")

</div>

Hi,  
can someone please give me a hint how to parse expressions in a NotificationProfileProperty?  
I figured out how to get the raw value of the property from the NotificationContext, but now have no idea how to parse this raw message to resolve the referenced properties.  
In the javadocs there’s a class AlarmEventCollectionExpressionParseContext that seems to be related, but there’s no description of the implementation.  
A little example would be great.

Thank you,  
Carsten

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 4, 2013, 11:06pm UTC](https://forum.inductiveautomation.com/t/alarmnotification-how-to-parse-expressions-in-a-property/7655/2 "2013-12-04T23:06:15Z")

</div>

This is how the email profile evaluates its subject and message properties as an example:

```auto
		private String evaluate(String expressionString, List<AlarmEvent> alarmEvents) {
			if (StringUtils.isBlank(expressionString)) {
				return "";
			}

			AlarmEventCollectionExpressionParseContext ctx = new AlarmEventCollectionExpressionParseContext(
					new FallbackPropertyResolver(context.getAlarmManager().getPropertyResolver()), alarmEvents);
			ExpressionParseContext parseContext = new LegacyAlertPropParseContext(new FormattedExpressionParseContext(ctx));

			String evaluated = expressionString;

			try {
				QualifiedValue value = parser.parse(ctx.expandCollectionReferences(expressionString), parseContext)
						.execute();
				if (value.getQuality().isGood()) {
					evaluated = TypeUtilities.toString(value.getValue());
				}
			} catch (Exception e) {
				log.error(String.format("Error parsing expression \"%s\".", expressionString), e);
			}

			return evaluated;
		}
```

Pretty straightforward… right? right? eh…

---

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [December 5, 2013, 6:13pm UTC](https://forum.inductiveautomation.com/t/alarmnotification-how-to-parse-expressions-in-a-property/7655/3 "2013-12-05T18:13:19Z")

</div>

Thank you, that helped. Now that i understand the concept of nested parse contexts and the use of the Parser class it makes sense.  
The LegacyAlertPropParseContext must be a non-api class, so i simply left it away.

[quote]Pretty straightforward… right? right? eh…[/quote]Yes, that’s what i always tell people when i got no time for documentation: That’s totally straight forward, you don’t need documentation.  
Works perfect until ten years later, when i’m called to repair a machine and wonder what ### wrote that ### code. Normally i realize after some minutes that it was me 😉.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [December 10, 2013, 5:11pm UTC](https://forum.inductiveautomation.com/t/alarmnotification-how-to-parse-expressions-in-a-property/7655/4 "2013-12-10T17:11:25Z")

</div>

You can make your own parse context. We extended ExpressionParseContext as follows:

```auto
public class MyExpressionParseContext implements ExpressionParseContext {

	@Override
	public Expression createBoundExpression(String path)
			throws RuntimeException {
		TagPath tagPath;
		try {
			tagPath = TagPathParser.parse(path);
			BoundTagExpression exp = new BoundTagExpression(tagPath);
			exp.setTagListenerDelegate(new com.inductiveautomation.ignition.common.expressions.TagListener(
					tagPath, null, DataQuality.UNKNOWN));
			return exp;
		} catch (IOException e) {
			return null;
		}
	}

	@Override
	public FunctionFactory getFunctionFactory() {
		return DefaultFunctionFactory.getSharedInstance();
	}

}
```

Note that DefaultFunctionFactory.getSharedInstance() is deprecated. Possible replace that with new ContextDelegateFunctionFactory(context)?
