Storing ticket data

You can also store data in Custom Fields which are created by your application. This method has the advantage that your Custom Fields can be used with Ticket Filters and Triggers to create powerful automations.

If you are not yet familiar with the concept of Custom Fields in Deskpro, head over to the official documentation: https://support.deskpro.com/en/guides/admin-guide/ticket-fields-2/custom-fields

How does it work?

You declare custom fields and their type in your application manifest. The custom fields are created when the application is installed and they become available through the Deskpro REST API and will also appear in the admin interface, where you can include them in Filters and Triggers.

Unlike regular custom fields, these custom fields can not be deleted while your application is installed.

Here is an example of declaring a Ticket Custom Field of type text with an alias and a title

  {
      "customFields": [
        {
          "type": "text",
          "attachedTo": "ticket",
          "alias": "myField",
          "title": "My Field"
        }
      ]
  }

Available Types

For in-depth coverage of Custom Fields definition, see the customTypes section from the Manifest reference.

Using the Custom Fields Client

The Custom Fields Client allows you to read and write custom field values from the Deskpro Object specific to the target in which the application is running. It can work for both regular Custom Fields and Application Custom Fields.

Application Custom Fields are referred to by their alias which must be always defined in your application manifest. The following snippet shows you how to write and read a custom field using the Custom Fields Client:

  // obtain a reference to the Custom Fields Client from the Application Context

  const { 
      /**
       * @see https://deskpro.github.io/apps-sdk-core/reference/CustomFieldsClient.html
       */
      customFields
  } = dpapp.context;

  // save the value of an application's custom field
  customFields.setAppField('myField', ['867-5309', 867]);

  // read the value of an application's custom field
  customFields.getAppField('myField').then(value => console.log(value));

For more usage examples, see this recipe: Access Custom Fields

Last updated