P4JSAPI to P4V-JS Conversion Guide (2019.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.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.getPort()

Returns a string containing the Helix server connection setting.

p4vjs.getUser()

Returns a string containing the current user.

p4vjs.getServerRootDirectory()

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

p4vjs.getServerVersion()

Returns a string containing the server version number.

p4vjs.isServerUnicode()

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

p4vjs.isServerCaseSensitive()

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

p4vjs.getServerSecurityLevel()

Returns a string containing the server’s security level.

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.getImage(image)

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

p4vjs.getSelection()

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

p4vjs.setSelection(selectionList)

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

p4vjs.refreshAll ()

Forces a refresh of P4V.

p4vjs.openUrlInBrowser(url)

Launches the default web browser and displays the specified URL.

p4vjs.setP4VErrorDialogEnabled(true|false)

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

p4vjs.closeWindow()

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

p4vjs.useDarkTheme()

Returns true if P4V is in dark theme mode.