The substitute script step does always execute / evaluate the last element of the command
Operating system version
Description of the issue
When you use the substitute command in a formula the last expression of the command is being evaluated always and not only when there is something to be replaced. This is a major performance issue!
Steps to reproduce the problem
Substitute( "test" ; "abc" ; Let( $$variable = 5 ; "" ) )
substitute returns test, $$variable is not set
substitute return test, $$variable is 5
check the existence of the to be replaced value before actually substituting the value. This is also a bit a performance issue, hence you actually need to search the occurrences in the text twice if there are any occurrences to be replaced.
if ( PatternCount( "test" ; "abc" ) > 0 ; Substitute( "test" ; "abc" ; Let( $$variable = 5 ; "" ) ) ; "test" )