User Activity

I am unable redirect to any URL using setRedirect in server side script of the widget i am working on. Can someone help on how can we do that or where is the issue.Added the code snippets.
For a notification(email invitation) when triggers the email content is blank for some recipients while for others it is coming fine. Is there any known issue or any reason why this is happening.
I have got this error -  'Server JavaScript error Cannot read property "view" from undefined' after changes on a widget and loading the form. Any idea why this is coming?error screenshot: Code screenshots:  
Helpfuls given to