How to execute script from clientΒΆ

You can use server method to send a request to the server to execute a function defined in the server module of an item.

In the example below we create the btn button that is a JQuery object. Then we use its click method to attach a function that calls the server method of the item to run the calculate function defined in the server module of the item.

The code in the client module:

function on_view_form_created(item) {
    var btn = item.add_view_button('Calculate', {type: 'primary'}); {
        item.server('calculate', [1, 2, 3], function(result, error) {
          if (error) {
          else {

The code in the server module:

def calculate(item, a, b, c):
    return a + b + c