Developer Portal for YouTrack and Hub Help

Demo Import Script

In this article, we look closely at the demo script package, explain how it is built and what is the logic behind it.

Demo Script Package

To get an idea of how a custom import script works, have a look at the predefined demo import script package that is built in to your YouTrack.

To open the demo import script package:

  1. From the Administration menu, select Integrations > Imports.

  2. Click the New import button to open the setup dialog.

    New import dialog
  3. Select Custom import.

    • The New Custom Import dialog opens.

  4. Make sure that in the Import script package dropdown menu, the default @jetbrains/youtrack-demo-client script is selected.

    Select demo client
  5. Click the customize import script link at the bottom of the page.

    • The web-based script editor opens with the demo script package expanded. To learn about working in the web-based script editor, see Web-based Workflow Editor.

The demo script package consists of five files. The main script file is named client.js. It contains the import logic and the API reference. Consult this file as an example of an import script.

The other four files contain hard-coded demo data in JSON format. This data is then converted into YouTrack entities when the demo import script is run.

Data for the demo client

These four files show you what attributes can be imported for issues, articles, projects, and users. Consult these files to learn which data format is expected from the import source.

Demo Client Script

Here you can find the content of the client.js file from the demo script package. For better readability, the content of the file is stripped of the API reference.

const demoIssue = require('./demo-issue').demoIssue; const demoArticle = require('./demo-article').demoArticle; const demoUser = require('./demo-user').demoUser; const demoProject = require('./demo-project').demoProject; class DemoClient { constructor(context) { const params = context.parameters; this.url = params.loadValue('url'); this.sslKeyName = params.loadValue('sslKeyName'); this.token = params.loadValue('password'); this.connection = new http.Connection(this.url, this.sslKeyName).addHeader('Authorization', this.token); } prepareToImport() {} getTimestampFormats() { return ['yyyy-MM-dd\'T\'HH:mm:ss\'Z\'', 'yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'', 'yyyy-MM-dd']; } getServerInfo() { return { version: 'demo', time: new Date().toISOString() }; } getAttachmentContent(project, document, attachment) { return { data: '', metadata: { mimeType: 'image/jpeg' } }; } getLinkTypes() { return []; } getProject(projectInfo) { return demoProject; } getProjects() { return [demoProject]; } getIssues(projectInfo, after, top) { return [demoIssue]; } getUsers(group, skip, top) { return [demoUser]; } getIssueUpdates(projectInfo, after, updatedAfter, top) { return [demoIssue]; } getUserTimeZoneId() { return 'Europe/London'; } getArticles(projectInfo, after, top) { return [demoArticle]; } } exports.Client = context => new DemoClient(context);
Last modified: 23 April 2024