Options
All
  • Public
  • Public/Protected
  • All
Menu

Coding Card

The Coding Card API exposes functionality used to create and manage the coding cards. For the API reference, see ICodingCard.

The following extension script illustrates how to use these features of the Coding Card API:

  • Example 1 - retrieve the coding card object.
  • Example 2 - change the mode of a coding card.
  • Example 3 - save a coding card.
  • Example 4 - use the Relativity Forms API. For more information, see Relativity Forms API.
  • Example 5 - add buttons to the coding card toolbar and remove them.
// Example 1
// Get the coding card object.
var codingCard = review.viewer.mainCollection.codingCards[0].instance;

//---------------

// Example 2
// Change the mode of the coding card.

// Change the mode from view -> edit.
await codingCard.editAsync();

// Change the mode from edit -> view.
await codingCard.cancelAsync();

// Change the reviewMode using the configuration service.
review.configuration.updateSetting("reviewMode", "Edit");

//---------------

// Example 3
// Save the coding card.

// Save
await codingCard.saveAsync();

// Save and Next
await codingCard.saveAndNextAsync();

// Save and Back
await codingCard.saveAndBackAsync();

//---------------

// Example 4
// Use the convenienceAPI object in the Relativity Forms API.

var convenienceAPI = codingCard.getConvenienceAPI();

var documentId = review.viewer.mainCollection.queuePointer.item.artifactId;
var workspaceId = review.configuration.workspaceId;
var formParams = {
  workspaceId,
  artifactTypeId: 10,
  artifactId: documentId,
};
await convenienceAPI.navigation.navigateToForm("edit", formParams);

//---------------

// Example 5
// Add buttons to the toolbar and remove them.

var buttonToAdd = {
  id: "_checkoutNextItemButton",
  name: "Checkout Next Item",
  slotPosition: "left",
  visibleMode: [2],
  isDisabled: false,
  className: "",
  order: 2,
  onClick: async () => {
    const currentIndex = review.viewer.mainCollection.queuePointer.index;
    const queueLength = review.viewer.mainCollection.queuePointer.queue.length;
    if (currentIndex + 1 === queueLength) {
      // Add another item to the end of the queue.
    }
    await codingCard.saveAndNextAsync();
  },
  onBuild: () => {
    const currentIndex = review.viewer.mainCollection.queuePointer.index;
    const queueLength = review.viewer.mainCollection.queuePointer.queue.length;
    // Return true, which displays the button, if you're the end of the queue.
    return currentIndex === queueLength - 1;
  },
};

// Get all the registered buttons.
var codingCardButtons = codingCard.buttons;

// Search for a button.
var saveAndBackButton = codingCardButtons.find((button) => {
  return button.id === "_saveAndBackButton";
});

// Make sure the buttonToAdd displays in the same order as the button you removed.
buttonToAdd.order = saveAndBackButton.order;

// Remove the old button.
codingCard.removeButton(saveAndBackButton.id);

// Add a new button.
codingCard.addButton(buttonToAdd);