The chat responses are generated using Generative AI technology for intuitive search and may not be entirely accurate. They are not intended as professional advice. For full details, including our use rights, privacy practices and potential export control restrictions, please refer to our Generative AI Service Privacy Information. As this is a test version, please let us know if something irritating comes up. Like you get recommended a chocolate fudge ice cream instead of an energy managing application. If that occurs, please use the feedback button in our contact form!
Skip to content

Your first application

2612

In this walkthrough you build Hello Polarion: a form extension that shows a greeting and nothing else. No SDK, no state, no calls to Polarion; the point is the development loop, and you go through every step of it once: create the project, write the view, package the ZIP, upload it, and place it in a work item form. Reading the context and calling Polarion come next, in the Application context example.

The finished Hello Polarion panel inside a work item of the Drive Pilot demo project

The complete source is in examples/hello-polarion, where you can also download the finished application package and the source project. You can follow along from scratch or open the example side by side.

Before you start

Make sure the prerequisites are met and that an administrator has enabled Applications on your Polarion server. You need the host name of that server; the walkthrough uses polarion.example.com as a placeholder.

1. Create the project

  1. Scaffold a Vite project with the React + TypeScript template and install its dependencies:

    npm create vite@latest hello-polarion -- --template react-ts
    cd hello-polarion
    npm install
    
  2. Make Vite emit relative asset URLs. Polarion serves the view from a sub-path such as /polarion/apps/com.example.hello/hello/, so absolute /assets/… URLs would not resolve. Replace vite.config.ts with:

    vite.config.ts
    import { defineConfig } from "vite";
    import react from "@vitejs/plugin-react";
    
    // https://vite.dev/config/
    export default defineConfig({
      plugins: [react()],
      // Polarion serves the view from a sub-path such as
      // /polarion/apps/<identifier>/<rootDirectory>/, so all asset URLs must be relative.
      base: "./",
    });
    
  3. Remove the template files you do not need (src/App.css, src/index.css, src/assets/, public/vite.svg) and make sure index.html is a plain host page:

    index.html
    <!doctype html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Hello Polarion</title>
      </head>
      <body>
        <div id="root"></div>
        <script type="module" src="/src/main.tsx"></script>
      </body>
    </html>
    

2. Describe the application: manifest.json

Create manifest.json in the project root. It tells Polarion what the application is called and which views it contains.

manifest.json
{
  "manifestVersion": "1.0",
  "identifier": "com.example.hello",
  "title": "Hello Polarion",
  "description": "The smallest possible Polarion Application: one form extension that says hello.",
  "publisherName": "Example Publisher",
  "applicationVersion": "0.2.0",
  "views": {
    "formExtensions": [
      {
        "identifier": "hello",
        "title": "Hello Polarion",
        "rootDirectory": "hello",
        "document": "index.html"
      }
    ]
  }
}

What the fields mean:

FieldMeaning
identifierUnique name of the application on the server. Reverse-DNS style (com.example.hello) is recommended. It becomes part of every URL and configuration id, so keep it short and stable.
manifestVersion, title, description, publisherName, applicationVersionShown to the administrator during upload and in Properties.
views.formExtensions[0].identifierThe view id. Together with the application identifier it forms the id used in configuration: com.example.hello.hello.
rootDirectory, documentWhere the view's files live inside the package and which file is the entry page.

The full schema is in the manifest.json reference.

3. Write the view

  1. Replace src/main.tsx:

    src/main.tsx
    import { StrictMode } from "react";
    import { createRoot } from "react-dom/client";
    import App from "./App";
    import "./styles.css";
    
    createRoot(document.getElementById("root")!).render(
      <StrictMode>
        <App />
      </StrictMode>,
    );
    
  2. Replace src/App.tsx. The view is an ordinary React component; nothing in it is specific to Polarion:

    src/App.tsx
    export default function App() {
      return (
        <main>
          <h1>Hello, Polarion</h1>
          <p>This panel is a Polarion Application.</p>
        </main>
      );
    }
    

    What makes it a Polarion Application is the packaging: the manifest, the ZIP layout and the place in the form layout, in the next steps. The page does not need the SDK to be shown; the SDK comes in when the view wants to know where it is or call Polarion.

  3. Add src/styles.css with a little styling:

    src/styles.css
    body {
      margin: 0;
      padding: 12px;
      font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
      font-size: 14px;
      color: #1f2933;
    }
    
    h1 {
      font-size: 1.4rem;
      margin: 0 0 8px;
    }
    
  4. Build once to check that everything compiles:

    npm run build
    

    Vite writes dist/index.html and dist/assets/…. Open dist/index.html and confirm that the script and stylesheet paths start with ./assets/.

4. Package the ZIP

Polarion expects a ZIP with one top-level folder named after the identifier. Inside it: manifest.json, one folder per view (named like rootDirectory), and optionally server-scripts/.

  • com.example.hello.zip
    • com.example.hello/
      • manifest.json
      • hello/
        • index.html
        • assets/
          • index-….js
          • index-….css

A ZIP with manifest.json directly at its root is rejected with Application's zip structure is incorrect. For the file types a package may contain and its size limits, see Allowed file types and Validation and limits.

Add scripts/package.mjs and the dev dependency adm-zip. The script copies the build into the right layout and writes the ZIP:

npm install --save-dev adm-zip
scripts/package.mjs
// Builds the upload-ready ZIP for Polarion.
//
// Layout inside the ZIP: one top-level folder named after the application
// identifier, with manifest.json, view content under each view's
// rootDirectory (which multiple views may share), and optional server-scripts/.
// Polarion rejects a ZIP that has manifest.json directly at its root
// ("Application's zip structure is incorrect").
//
//   <identifier>/
//     manifest.json
//     <rootDirectory of each view>/   (index.html + assets)
//     server-scripts/                 (if present)
//
// Single-view projects build into dist/. Multi-view projects build one Vite
// mode per view into dist/<rootDirectory>/ (see "Set up the project" in the
// guide); this script copies whichever exists.
//
// Run with `npm run package` (which builds first).
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import AdmZip from "adm-zip";

const projectRootPath = fileURLToPath(new URL("..", import.meta.url));
const distributionPath = join(projectRootPath, "dist");

function stageViews(appStagePath, manifest) {
  const views = Object.values(manifest.views ?? {}).flat();
  if (views.length === 0) {
    throw new Error("manifest.json declares no views.");
  }

  for (const view of views) {
    const viewDist = join(distributionPath, view.rootDirectory);
    const source = existsSync(viewDist) ? viewDist : distributionPath;
    const documentPath = join(source, view.document);

    if (!existsSync(documentPath)) {
      throw new Error(`Build output for view "${view.identifier}" not found: ${documentPath}`);
    }
    cpSync(source, join(appStagePath, view.rootDirectory), { recursive: true });
  }
}

function stageServerScripts(appStagePath) {
  const serverScripts = join(projectRootPath, "server-scripts");
  if (existsSync(serverScripts)) {
    cpSync(serverScripts, join(appStagePath, "server-scripts"), { recursive: true });
  }
}

function writePackageZip(stageRoot, zipPath) {
  const zip = new AdmZip();
  zip.addLocalFolder(stageRoot);
  zip.writeZip(zipPath);
}

function packageApplication() {
  const manifest = JSON.parse(readFileSync(join(projectRootPath, "manifest.json"), "utf8"));
  const stageRootPath = join(projectRootPath, "package");
  const zipPath = join(projectRootPath, `${manifest.identifier}.zip`);

  rmSync(stageRootPath, { recursive: true, force: true });
  try {
    const appStagePath = join(stageRootPath, manifest.identifier);
    mkdirSync(appStagePath, { recursive: true });
    cpSync(join(projectRootPath, "manifest.json"), join(appStagePath, "manifest.json"));
    stageViews(appStagePath, manifest);
    stageServerScripts(appStagePath);
    writePackageZip(stageRootPath, zipPath);
  } finally {
    rmSync(stageRootPath, { recursive: true, force: true });
  }

  console.log(`Packaged ${manifest.identifier} ${manifest.applicationVersion} -> ${zipPath}`);
}

packageApplication();

Then add two npm scripts to package.json and run the packaging:

package.json (scripts)
"scripts": {
  "dev": "vite",
  "build": "tsc -b && vite build",
  "package": "npm run build && node scripts/package.mjs"
}
npm run package
# Packaged com.example.hello 0.2.0 -> …/com.example.hello.zip
npm run build
rm -rf package && mkdir -p package/com.example.hello
cp manifest.json package/com.example.hello/
cp -R dist package/com.example.hello/hello
(cd package && zip -r ../com.example.hello.zip com.example.hello)
npm run build
Remove-Item -Recurse -Force package -ErrorAction Ignore
New-Item -ItemType Directory package\com.example.hello | Out-Null
Copy-Item manifest.json package\com.example.hello\
Copy-Item -Recurse dist package\com.example.hello\hello
Compress-Archive -Path package\com.example.hello -DestinationPath com.example.hello.zip -Force

5. Upload the application

  1. In Polarion open Global Administration → Applications and click Upload.

  2. Choose com.example.hello.zip and click Next.

    Upload Application dialog, step 1: choose the ZIP file

  3. Polarion validates the package and shows what it is about to install: identifier, version, title, publisher and the SHA-2 hash of the file. Compare the hash with the one you computed if your organization requires it, then click Finish.

    Upload Application dialog, step 2: review identity and hash, then Finish

  4. A green bar confirms Application 'com.example.hello' was uploaded and the tile appears in the list. Hover the tile to see the description; select it and click Properties to see the manifest data.

    The Applications page after a successful upload

The application is now installed but not yet visible anywhere. Views have to be placed.

6. Place the view in a work item form

Form extensions are positioned by the administrator in the form layout of a work item type, per project.

  1. Open your project and go to Administration → Work Items → Form Configuration.

  2. In the Form Layouts table at the bottom of the page, click Edit next to the work item type you want to extend (for example Task). If the type has no layout yet, click Create New Form Layout first.

  3. In the XML editor, insert an applicationView element where the panel should appear. The id is <identifier>.<viewId>:

    Form layout (excerpt)
    <formLayout …>
      <horizontal>
        …
      </horizontal>
      <applicationView id="com.example.hello.hello" label="Hello Polarion" height="320px"/>
      <field id="description"/>
      <field id="comments"/>
      …
    </formLayout>
    

    label sets the heading of the panel (default: Polarion Application). height sets the height of the iframe.

    Form layout editor with the applicationView element inserted

  4. Click Save. The message Configuration has been saved appears.

  5. Open any work item of that type. Reload the page if it was already open. The Hello Polarion panel shows the greeting.

    Hello Polarion rendered in the work item form

If a Warning dialog appears

A dialog saying X-Rest-Token generation is not allowed on the server means the server lacks REST token authentication. The panel still renders, but REST calls will fail; see Enable Applications in Polarion.

What you have learned

  • An application is a ZIP with a manifest and static views; Polarion serves it from /polarion/apps/<identifier>/.
  • The view itself is an ordinary web page; it needs no SDK to be shown.
  • Views are placed with <applicationView id="<identifier>.<viewId>"/> in configuration XML.

Continue with Iterate: change, rebuild, re-upload to learn the development loop. To see what a view learns about its surroundings, install the Application context example; the Work item card then shows the REST API in action.