Scripting on Forms
Forms support two scripting hooks that let you encode business rules at the form level — one that runs before the form renders, and one that runs after every successful transaction.
For the variables available in each hook, see Scripting Contexts.
Pre-Processing Script
When it runs: Before the form renders, each time a donor opens the page.
What it can do:
- Look up the logged-in user’s record and pre-populate form fields from their data
- Set default field values from URL parameters passed to the form
- Redirect the donor to a different page based on context (for example, redirect an already-pledged employee to their giving history)
- Initialize custom field values based on campaign configuration
Example — pre-populate from employee record:
import "employeeRelationshipService";
if (user != null) {
var emp = employeeRelationshipService.findByContact(contact, account);
if (emp != null) {
purchaseOrder.get('Department').value = emp.get('Department').value;
purchaseOrder.get('Workgroup').value = emp.get('Workgroup').value;
}
}
Post-Processing Script
When it runs: Once, after every successful transaction from this form — after the transaction is saved and all item-level post-processing scripts have run.
What it can do:
- Send custom notifications beyond the standard receipt email
- Update related records (for example, update a contact’s donor status)
- Post transaction data to an external system
- Create follow-up tasks or opportunities
- Trigger a matching gift check
Example — notify coordinator of major gift:
import "mailer";
if (purchaseOrder.amount >= 1000) {
mailer.sendEmail(
account.getProperty('majorGiftsEmail'),
'New major gift received',
contact.firstName + ' ' + contact.lastName +
' gave $' + purchaseOrder.amount
);
}
Where Scripts Are Configured
Both scripts are configured on the Integration tab of the Form edit page, in the Pre-Processing Script and Post-Processing Script fields.
Scripts are written in JavaScript. The full scripting language reference, available services, and patterns are in the Scripting Guide.