Developer Portal for YouTrack and Hub Help

Form API Reference

Here you can find the reference for the Form API and learn how to establish a connection to the form.

Establish a Connection

The first step for using the Form API is establishing a connection to the form. To do that, use the sample code below with the ID of the form you're working with.

YTFeedbackForm.getClientJSApi('680e7600-000f-4029-bfe9-ddf479c73ef7').then(async form => { // Your code goes here })

You can get the form ID from the embed code for the form.

The form ID in the embed code viewed in Popup mode.
The form ID in the embed code viewed in Popup mode.

Predefined Fields

There are three predefined form fields that you can refer to by their names:

  • email
  • summary
  • description

Sample code:

// Setting the email value to jane.doe@example.com. form.setBlockValue('email', 'jane.doe@example.com'); // Setting the summary. form.setBlockValue('summary', 'Assistance Required'); // Setting the description. form.setBlockValue('description', 'I need assistance, please get back to me.');

Methods

getBlocks

The getBlocks method lets you get the blocks available for the form.

Sample: getBlocks()

Returned Value

Type

Description

Array<Block>

An array of blocks available for the form.

getBlockValue

The getBlockValue method lets you get the value of the particular block in the form. This method is useful when you need to prefill a block value based on a value entered by the user in another block.

Sample: getBlockValue(blockReference)

Parameters

Name

Type

Description

blockReference

String

The ID or the title of the block.

Returned Value

Type

Description

Value

The value of the block.

getBlockValues

The getBlockValues method lets you get the list of available values for the particular block in the form. Works only when the block is represented by an enumerated custom field in YouTrack.

Sample: getBlockValues(blockReference)

Parameters

Name

Type

Description

blockReference

String

The ID or the title of the block.

Returned Value

Type

Description

Array<Value>

An array of available values for the block.

setBlockValue

The setBlockValue method lets you set the value in a block in the form.

Sample: setBlockValue(blockReference, newValue)

Parameters

Name

Type

Description

blockReference

String

The ID or the title of the block.

newValue

String

The new value for the block. For the values of an enumerated field, you can use the ID of the corresponding block value.

Last modified: 7 November 2024