Issue when generating substring

I finally found out (after several close/reopen and several days) what was the cause of the annoyng “Cannot Generate Steps” errors when I try to record some steps.

1- I created a test case using the record tool
2- I need a serial code that is generated for each transaction, so I located the web element, get the text and use the substring method of Kotlin.
3- I tried this:
varieableX = WebUI.getText(findTestObject(‘Object Repository/Page_New Transaction/’)).substring(14, 20))
4- Perform another user actions, like 4-5 more actions (some clicks and navigation to a different page)
5- Use variableX to enter text in a new field:
WebUI.setText(findTestObject(‘Page_Search Transactions/<element’), variableX

If I run the test case, it runs successfully, but if I want to add more steps using the recording option I get the alert “Cannot Generate steps” and that feature stop working for all the test cases, I cannot longer use the recording tool. I have to close/reopen Katalon to be able to use the recording feature, but if I try to use it again in the test case mentioned above, the error is back.

I noticed that the error does not happen when I move the .substring(14, 20)) to the end of the script(where I use the variable) instead of where the variable is created (step 3)

Thank you