Maybe the problem with your script is that itβs outputting the incremented number onto the produced HTML page? There are several solutions to this:
Somebody did this recently here in the SuiteCRM forums using arrays and math:
https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/27306-variables-on-tpl-files#88921