Skip to main content

Expenses

The Expenses module provides access to contextual information about the current expense when a widget is rendered within supported expense-related pages. Widgets can retrieve expense identifiers, category details, and related accounting metadata for use in validations, conditional logic, and UI extensions.

Events

Events

ON_EXPENSE_PAGE_LOAD

This event is triggered when the widget is loaded for the first time on the expense page. You can use this event to initialize data, fetch required resources, or set up the initial state of your widget.

Supported Locations :
expense.creation.sidebar
Sample Code :
REQUEST DETAILS
ZFAPPS.extension.init().then(function(App) {
  App.instance.on('ON_EXPENSE_PAGE_LOAD').then(async function() {
    // Set default value for a custom field
    await ZFAPPS.set('expense.cf_priority_level', 'Normal');

    ZFAPPS.invoke('SHOW_NOTIFICATION', {
      type: 'success',
      message: 'Default priority level has been set to Normal.'
    });
  }).catch(function(err) {
    console.error('Error:', err);
  });
});

ON_EXPENSE_PRE_SAVE

This event is triggered just before the expense record is saved in your organization. It allows your widget to validate data, modify field values, or perform custom checks before the save operation is completed.

Supported Locations :
expense.creation.sidebar
Sample Code :
REQUEST DETAILS
ZFAPPS.extension.init().then(function(App) {
  App.instance.on('ON_EXPENSE_PRE_SAVE').then(async function() {

    var record = await ZFAPPS.get('expense');
    record = record?.['custom_fields'];

    if (record.cf_approval_required && !record.cf_approval_notes) {

      await ZFAPPS.invoke('SHOW_NOTIFICATION', {
        type: 'error',
        message: 'Approval notes are required when Approval Required is selected.'
      });

      return {
        prevent_save: true
      };
    }

  }).catch(function(err) {
    console.error('Error:', err);
  });
});