Customize a form template by using a script - Microsoft Support
Adding script enables you to customize your form template beyond what is available with rules, formulas, data validation, or conditional formatting. For example, you can add a script that creates and sends an e-mail message when a user switches the view in a form based on your form template.
Applies To:
InfoPath 2010, InfoPath 2013