Get Revisions



Get all revisions

  • Use getFor to retrieve all of the revisions currently kept for the specified document.

Example:

// Get revisions for document 'orders/1-A'
const orderRevisions = await session.advanced.revisions
    .getFor("orders/1-A", {
        start: 0,
        pageSize: 10
    });

Syntax:

// Available overloads:
await session.advanced.revisions.getFor(id);
await session.advanced.revisions.getFor(id, options);
Parameters Type Description
id string Document ID for which to retrieve revisions
options options object Used for paging

// options object
{
    start,   // The first revision to retrieve, used for paging. Default is 0.
    pageSize // Number of revisions to retrieve per results page. Default is 25.
}
Return value
Promise A Promise resolving to the document's revisions.
Revisions will be ordered by most recent revision first.

Get revisions metadata

  • Use getMetadataFor to retrieve the metadata for all the revisions currently kept for the specified document.

Example:

// Get revisions' metadata for document 'orders/1-A'
const orderRevisionsMetadata = await session.advanced.revisions
    .getMetadataFor("orders/1-A", {
        start: 0,
        pageSize: 10
    });

// Each item returned is a revision's metadata, as can be verified in the @flags key
const metadata = orderRevisionsMetadata[0];
const flagsValue = metadata[CONSTANTS.Documents.Metadata.FLAGS];

assertThat(flagsValue).contains("Revision");

Syntax:

// Available overloads:
await session.advanced.revisions.getMetadataFor(id);
await session.advanced.revisions.getMetadataFor(id, options);
Parameters Type Description
id string Document ID for which to retrieve revisions' metadata
options options object Used for paging

// options object
{
    start,   // The first revision to retrieve, used for paging. Default is 0.
    pageSize // Number of revisions to retrieve per results page. Default is 25.
}
Return value
Promise A Promise resolving to a list of the revisions metadata.

Get revisions by creation time

  • Use get to retrieve a revision by its creation time.

Example:

// Creation time to use, e.g. last year: 
const creationTime = new Date();
creationTime.setFullYear(creationTime.getFullYear() - 1);

// Get a revision by its creation time
// If no revision was created at the specified time,
// then the first revision that precedes it will be returned
const orderRevision = await session.advanced.revisions
    .get("orders/1-A", creationTime.toLocaleDateString());

Syntax:

await session.advanced.revisions.get(id, date);
Parameter Type Description
id string Document ID for which to retrieve the revision by creation time
date string The revision's creation time
Return value
Promise A Promise resolving to the revision.
If no revision was created at the specified time, then the first revision that precedes it will be returned.

Get revisions by change vector

  • Use get to retrieve a revision or multiple revisions by their change vectors.

Example:

// Get revisions metadata 
const revisionsMetadata = await session.advanced.revisions
    .getMetadataFor("orders/1-A", {
        start: 0,
        pageSize: 25
    });

// Get the change-vector from the metadata
var changeVector = revisionsMetadata[0][CONSTANTS.Documents.Metadata.CHANGE_VECTOR];

// Get the revision by its change-vector
const orderRevision = await session.advanced.revisions
    .get(changeVector);

Syntax:

// Available overloads:
await session.advanced.revisions.get(changeVector);
await session.advanced.revisions.get(changeVectors);
Parameter Type Description
changeVector string The revision's change vector
changeVectors string[] Change vectors of multiple revisions
Return value
Promise A Promise resolving to the matching revision(s).