Client scripts can be very useful for basic field validation and automation. The benefit of client scripts is that you can perform actions in real time as you edit a transaction. A client script runs in the browser rather than on the server, and that enables you to perform certain actions that cannot be done with a User Event script. For instance, you can use a confirmation or alert popup with a Client script but not with a User Event script. Below are the triggers associated with client scripts and some ways in which they can be used.
- Field Changed: triggers an action when a field is changed on a transaction. Example – Check a box when the department is changed.
- Line Init: triggers an action when a line item is added. Example – Auto-populate the department field on the line item with the department on the main transaction level.
- Page Init: triggers an action when the record loads. Example – Populate default field values when creating a new record.
- Post Sourcing: triggers an action after a field is sourced from another field. Example – Changing the Vendor field may also automatically change the department field. Check a box after the department field gets sourced from the vendor field.
- Save Record: triggers an action when the save button is clicked but before the record is actually saved. Example – Give a confirmation popup if a line item exists with 0 quantity. The confirmation can say “Are you sure you want to save with 0 quantity for line x?”
- Sublist Changed: triggers an action when a line item inserted, removed, or edited. Example – If the quantity of a line item was changed to 0, give an alert popup that is was changed.
- Validate Delete: triggers an action when a line item is about to be deleted. This either allows that line to be deleted or prevents it from being deleted. Example – Prevent everyone from deleted a line item on a Vendor Bill except for Administrators and give an alert that says something like “You do not have access to delete this line. Please contact your system Administrator.
- Validate Field: triggers an action when a field is about to be changed. This either allows it to be changed or prevents it from being changed. Example – Allow only the next approver of a purchase order to change the status to “approved” and give an alert to everyone else that says “Only the approver has the rights to change this field.”
- Validate Insert: triggers an action when a line item is about to be inserted into a sublist. This either allows it to be inserted or prevents it from being inserted. Example – If there is no department selected, automatically select a default department and allow the line item to be inserted.
- Validate Line: triggers an action when a line item is about to be added. This either allows it to be added or prevents it from being added. Example – Allow only the Administrator or Advanced Payable Manager roles to add line items to a Vendor Bill and give a message to everyone else who makes an attempt to do so.
I have used a ton of client scripts for different purposes over the last several years, and I have always been happy with what can be accomplished with them. In later posts I will get into setting up an actual client script. If you have any questions, I would love to hear from you.