Notifications
Clear all

[Solved] Extended Auto properties, combining rules

0
Topic starter

Need to set a property value if a certain string is found in a different text property. In reality, I need to select a lookup value if that string is found. And if not I need to check if another string is found and if so select a different lookup. But let us take one step at a time and start with setting a simple text property if the string is found.

I tried to configure a combined Ternary operation with a Regex operation, but I can't get the combination to work.
The idea is that if the result of the Regex operation = 'xxx' then set output shall be 'yyy' else it shall be ''

I have tried different variations of this:

<<('<<REGEX('%PROPERTY_123%','(?<=\r\n)(?<value>xxx)(?=\r)','0')>>') = 'xxx' ? 'yyy' : ''>>
or
<<'<<REGEX('%PROPERTY_123%','(?<=\r\n)(?<value>xxx)(?=\r)','0')>>' = 'xxx' ? 'yyy' : ''>>

The result currently comes out as 
'<<('<<REGEX('the first line of text from property_123'

How should I combine the rules to get the desired results?
Is it possible to place the result in a lookup property if I get the result 'yyy' to match the lookup's display value (or ID)?

2 Answers
0

Hi Karl,

You always have such interesting cases going on! 😊

Unfortunately, M-Files doesn't always recognize \r\n reliably — and that’s the issue we’re facing with both the regex and the text replacement functionality.

Right below the Property Value field, there's a Replace newline characters option. If you select Yes, rule will replace \r\n with \s in your text field:

<<'<<REGEX('%PROPERTY_{PD.LongText}%', '(?<=\s)(?<value>xxx)(?=\s)', '0')>>' = 'xxx' ? 'yyy' : ''>>

 

image

 

This solution works well if xxx appears only as a separate line, but if it also shows up within other lines, the regex will match both instances. I hope you're working with the first scenario.

If not, unfortunately, we currently can’t extract the exact value cleanly. However, I’ve opened a User Story to add a "Custom" option to the Replace newline characters field. That way, in the future, you’ll be able to replace newlines with a custom set of characters that don’t appear elsewhere in the text — giving you more precise control.

Once this feature is implemented, I’ll make sure to let you know!

To answer your last question – yes, you can place the result in the lookup property! Let me know if you need further help with the implementation.

Best regards,

Nika

This post was modified 2 weeks ago 3 times by Nika Tilic
Karl Lausten Topic starter 18/06/2025 11:34 am

Thank you Nika,

That solved the first question. It is not always the ideal solution because you sometimes need to specify that the string must be found at the beginning of a line. It does not work to use ^ because it is always interpreted as "At start of string", not "..or line".
I have seen no problems in using \r\n in Regex functions in the Property Operations module. In fact, I use it a lot there and have never observed any issues. That could suggest that the problem is not in how M-Files interprets the Regex but rather in how it is delivered to M-Files.....

You did not answer my second question:
Is it possible to place the result in a lookup property if I get the result 'yyy' to match the lookup's display value (or ID)?

Karl Lausten Topic starter 18/06/2025 11:39 am

@nikatilic 

Just ran a quick test regarding the second question and can now confirm that it is possible to place the result directly into a lookup property if the result matches the display value of an item in the list.

Nika Tilic Nika Tilic 18/06/2025 1:29 pm

I'm glad to hear that placing the result in the lookup property works! Regarding the regex support, I'll let you know as soon as we enable replacement with a custom string.

Best regards,
Nika

0
Topic starter

I case anyone needs it in the future: I managed to use this to set a lookup property with one out of three options based on 3 different Regex configuration. The trick is to combine these in a rather long and complex string like the one shown below, and then to combine it with the Replace New Line option if relevant to the regex function.

<<'<<REGEX('%PROPERTY_123%', '(?<=\s<lookahead>\s)(?<value>\S*)(?=\s<lookbehind>)', '0')>>' = '<match 1>' ? '<result 1>' : '<<'<<REGEX('%PROPERTY_123%', '(?<=\s<lookahead>\s)(?<value>\S*)(?=\s<lookbehind>)', '0')>>' = 'match 2' ? 'Result 2' : '<<'<<REGEX('%PROPERTY_123%', '(?<=\s<lookahead>\s)(?<value>\S*)(?=\s<lookbehind>)', '0')>>' = 'match 3' ? 'result 3' : ''>>'>>'>>