You are reading the documentation for an outdated Corteza release. 2021.9 is the latest stable Corteza release.

Client scripts

Before submitting the form

Example use-cases:
  • calculate complex fields

  • value validation

  • pre-fill missing values

You can set the default value for a field in the module editor.

DevNote: provide some links.

Before submitting the form:
export default {
  label: "label goes here",
  description: "description goes here",

  triggers ({ before }) {
    return before('formSubmit')
      .for('ui:compose:record-page')
  },

  // If you don't need the Compose helper, remove it
  async exec ({ $record }, { Compose, console }) {
    // Note: you don't need to return the $record; it's provided by reference
    //       so any changes you do to the original object will be directly applied
    //

    if (['crm'].includes($record.module.namespace.slug.toLowerCase())) {
      // interested only in CRM namespace
      return
    }

    if (['lead'].includes($record.module.handle.toLowerCase())) {
      // interested only in Lead module
      return
    }
  },
}

Generic on click action

Example use-cases:
  • OAuth flows

  • send notifications

  • render documents

Generic on click action:
export default {
  label: "label goes here",
  description: "description goes here",

  triggers ({ on }) {
    return on('manual')
      // vv Don't remove the next line vv
      .uiProp('app', 'compose')
  },

  // If you don't need the Compose helper, remove it
  async exec (args, { Compose }) {
    // Code goes here
  },
}

Process record on click

Example use-cases:
  • email the record contact

  • email the record owner

  • generate report for the specific record

Process record on click:
export default {
  label: "label goes here",
  description: "description goes here",

  triggers ({ on }) {
    return on('manual')
      .for('compose:record')
      .where('module', 'module goes here')
      .where('namespace', 'namespace goes here')
      // vv Don't remove the next line vv
      .uiProp('app', 'compose')
  },

  // If you don't need the Compose helper, remove it
  async exec ({ $record }, { Compose }) {
    // Code goes here
    // Note: unless false or an error, the return value is ignored
  },
}