Developer Portal for YouTrack and Hub Help

Sample Script

When you embed the code snippet for the online form to your website, add an extra script block and prefill the form fields using JavaScript.

Here you can find sample JavaScript code that you can use with the embed code for your form when you deploy the form to your website. See the API reference and adjust the sample code to your needs.

<script> // Establishing the connection to the form. YTFeedbackForm.getClientJSApi('680e7600-000f-4029-bfe9-ddf479c73ef7').then(async form => { // Getting the list of blocks available for the form and storing it in a variable. const blocks = form.getBlocks() // 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.'); // Setting the Due date value to the current date. form.setBlockValue('due date', new Date()); // Getting the set of values for an enumerated field and storing it in a variable. const priorityBlock = blocks.find(b => b.title === 'Priority'); const priorityValues = await form.getBlockValues(priorityBlock.id); // Setting the value of a block. form.setBlockValue(priorityBlock.title, priorityValues[0]); }); </script>

For reference on the JavaScript Form API, see Form API Reference.

Last modified: 7 November 2024