P4JSAPI to P4V-JS Conversion Guide (2020.2)

Functions supported in P4VJS

The file p4vjs.js defines the P4VJS commands that you can use in your HTML page to communicate with P4V. To use the following functions, you need to include this file.

All P4VJS functions return a JavaScript Promise, an object representing the eventual completion (or failure) of an asynchronous operation and its resulting value.

p4vjs.p4( command [,form] [,callback] )

Runs the specified p4 command.

Command results are returned as JavaScript objects containing data in JSON format, composed of the following properties:

{
  [str] data: when tagged data returned, array of tag/value pairs
  int size: number of members in data array
  str error: server error text, if any
  str info: server info text, if any
  str text: text returned only by diff2 command
}

p4vjs.closeWindow()

Closes the hosting floating window. Only works with HTML Windows (not with HTML Tabs).

p4vjs.getApiVersion()

Returns a string containing the version (level) of the JavaScript API.

p4vjs.getCharset()

For Unicode-mode servers, returns a string containing the character set in use (P4CHARSET).

p4vjs.getClient()

Returns a string containing the client workspace name (P4V only).

p4vjs.getImage(image)

Returns a string containing the specified P4V image in HTML-embedded format. Use the names returned by getImageNames().

p4vjs.getImageNames()

Returns a string array containing a list of images used by P4V to indicate file type and status. For consistency with P4V, use these images in your applications.

p4vjs.getPort()

Returns a string containing the Helix server connection setting.

p4vjs.getSelection()

Returns a list of the folders and files that are currently selected in the depot pane.

p4vjs.getServerRootDirectory()

Returns a string containing the directory on the host machine where Helix server stores its metadata files.

p4vjs.getServerSecurityLevel()

Returns a string containing the server’s security level.

p4vjs.getServerVersion()

Returns a string containing the server version number.

p4vjs.getUrlIParameter("change")

Returns the value of the changelist. This is a P4VJS function for Submit in an HTML Action.

p4vjs.getUrlIParameter("submitshelved")

Returns true if the Submit dialog was launched from Submit Shelved Files. This is a P4VJS function for Submit in an HTML Action.

p4vjs.getUser()

Returns a string containing the current user.

p4vjs.isServerCaseSensitive()

Returns a string containing true or false, indicating whether the server is case-sensitive.

p4vjs.isServerUnicode()

Returns a string containing true or false, indicating whether the server is running in Unicode mode.

p4vjs.nextPage()

Shows the P4V Submit page. This is a P4VJS function for Submit in an HTML Action.

p4vjs.openUrlInBrowser(url)

Launches the default web browser and displays the specified URL.

p4vjs.refreshAll ()

Forces a refresh of P4V.

p4vjs.selectedDirectories()

Returns an array of the selected directories:

  • (HTML Action) - in the Submit Action pre-page, when submitting from the Workspace or Depot tree
  • (HTML Window) - when launching an HTML Tool while using depot syntax to specify a file or folder with the %d argument type, or multiple files or folders with the %D argument type

p4vjs.selectedFiles()

Returns an array of the selected files:

  • (HTML Action) - in the Submit Action pre-page, when submitting from the Workspace or Depot tree
  • (HTML Window) - when launching an HTML Tool while using workspace syntax to specify a file with the %f argument type, or multiple files with the %F argument type

p4vjs.setP4VErrorDialogEnabled(true|false)

Enables/disables the display of server errors in popup windows. (By default, display of server errors is enabled.)

p4vjs.setSelection(selectionList)

Given a list of paths and files, selects them in the depot pane.

p4vjs.useDarkTheme()

Returns true if P4V is in dark theme mode.