Do both alerts produce the same result? (both of them have the correct values in the variables?)

You may need to update your glide, too. It looks like you're trying to insert directly into the RITM table...I would recommend inserting into task (task)...also, I would take the setRedirectURL out of the function...and is there a reason you are only calling the update function if the window is undefined (does it work without that if statement) ??