Over time stopped working

Hi Team,

Below code snippet was working great from past few months. but now getting below error message:

code snippet:

<<foreach [facility in application.facilities.orderBy(f => f.sequence)]>>
<<if[facility.indexOf() == 0]>>
<<var[THAIPRODUCTNAME = facility.productTypeName]>>
<<var[ENGLISHPRODUCTNAME = facility.productTypeEnglishName]>>
<</if>>
<</foreach>>
<<[THAIPRODUCTNAME]>>

Error message:

java.lang.IllegalStateException: An error has been encountered while evaluating the expression or statement 'THAIPRODUCTNAME]>'. Can not get the value of variable 'THAIPRODUCTNAME' before it is set.

== Stack trace ==

temp fix: if i initialize THAIPRODUCTNAME its working but how it was wroking without initialization in past

@Sangamesh019

The exception text explains what is wrong. Most likely, the issue appears only when condition <<if[facility.indexOf() == 0]>> is not met, put simply, when application.facilities is empty.

If this is the case, then it is expected behavior rather than a bug and the reason why you did not observe this behavior earlier is that application.facilities was never empty before that. You have correctly identified the way to fix the issue by declaring the variable before the loop.

If this exception appears under other circumstances than empty application.facilities, then please share your sample template, data, and code reproducing the issue for further analysis on our end. If the issue started to appear after updating to a newer version of Aspose.Words, then please also specify an old version where it worked as expected and a new version where it does not.