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 you can use them.

Triggers

  1. Field Changed: triggers an action when a field is changed on a transaction. Example Check a box when the department is changed.
  2. 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.
  3. Page Init: triggers an action when the record loads. Example Populate default field values when creating a new record.
  4. 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.
  5. 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?”
  6. 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 it was changed.
  7. 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 deleting 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.”
  8. 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.”
  9. 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.
  10. 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.

Conclusion

I have used a ton of client scripts for different purposes over the last several years, and I have always been happy with what they can accomplish. For more scripting overviews, check out our blog covering some of the major script types. After learning about the main script types, you will be prepared to jump into our mini tutorial series on the basics of coding in SuiteScript 2.0 (a series which includes instruction on setting up an actual client script!).

If you have any questions, I would love to hear from you. And don’t forget to subscribe to our mailing list so you can receive our latest developing blogs directly in your inbox each week!