ERP Client Scripts - AngelAngelopoulos/ERPNext-CamundaBPM-Integration GitHub Wiki

Form Script

ERP allows the use of scripts, these scripts let add client side logic to the forms through javaScript.

*Note: this scripts also can be added in the server side by using Python.}

A {doctype}.js is always created when a new Doctype is created, this is where we can write the new form script

Syntax:

frappe.ui.form.on(doctype, {
    event1() {
        // handle event 1
    },
    event2() {
        // handle event 2
    }
})

After the use of the "form" it is neccessary to use a Form Event, this events triggers the Form Scripts. The Events use frm as the first parameter in their handler functions.

Form Events

Here are the list of the most common Form Events used:

  • setup - triggered once the form is created for the first time
  • before_load - triggered before the form is about to load
  • onload - triggered when the form is loaded and is about to render
  • refresh - triggered when the form is loaded and rendered.
  • onload_post_render - triggered after the form is loaded and rendered
  • validate - triggered before before_save
  • before_save - triggered before save is called
  • after_save - triggered after form is saved
  • before_submit - triggered before submit is called
  • on_submit - triggered after form is submitted
  • before_cancel - triggered before cancel is called
  • after_cancel - triggered after form is cancelled
  • timeline_refresh - triggered after form timeline is rendered
  • {fieldname}_on_form_rendered - triggered when a row is opened as a form in a Table field
  • {fieldname} - triggered when the value of fieldname is changed

Client Scripts

Client Scripts are Custom Form Scripts that were written for a specific logic used in a site.

Create a Client Script

To create a new Client Script to be used it´s neccessary to access the frappe framework, right in there the following steps are:

Home > Customization > Client Script > Click the "New" option

Client Script creation example