Without knowing much about suitescript specifically (and without digging into your snippet), I can answer "if you've got a function that calls itself, how do you get it to still finish the first call?" in general - you have to have a base case that exits at some point, before it calls itself again. Perhaps you need to test whether the field needs to be updated before trying to write out the update - if it's already been updated the value should match what you're trying to write, so the "trigger on update" shouldn't happen more than once, breaking the infinite loop.