Word.TrackedChange class

Represents a tracked change in a Word document.

Extends

Remarks

[ API set: WordApi 1.6 ]

Properties

author

Gets the author of the tracked change.

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

date

Gets the date of the tracked change.

text

Gets the text of the tracked change.

type

Gets the type of the tracked change.

Methods

accept()

Accepts the tracked change.

getNext()

Gets the next tracked change. Throws an ItemNotFound error if this tracked change is the last one.

getNextOrNullObject()

Gets the next tracked change. If this tracked change is the last one, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

getRange(rangeLocation)

Gets the range of the tracked change.

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

reject()

Rejects the tracked change.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Word.TrackedChange object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.TrackedChangeData) that contains shallow copies of any loaded child properties from the original object.

track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across .sync calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you need to add the object to the tracked object collection when the object was first created. If this object is part of a collection, you should also track the parent collection.

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You'll need to call context.sync() before the memory release takes effect.

Property Details

author

Gets the author of the tracked change.

readonly author: string;

Property Value

string

Remarks

[ API set: WordApi 1.6 ]

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

date

Gets the date of the tracked change.

readonly date: Date;

Property Value

Date

Remarks

[ API set: WordApi 1.6 ]

text

Gets the text of the tracked change.

readonly text: string;

Property Value

string

Remarks

[ API set: WordApi 1.6 ]

type

Gets the type of the tracked change.

readonly type: Word.TrackedChangeType | "None" | "Added" | "Deleted" | "Formatted";

Property Value

Word.TrackedChangeType | "None" | "Added" | "Deleted" | "Formatted"

Remarks

[ API set: WordApi 1.6 ]

Method Details

accept()

Accepts the tracked change.

accept(): void;

Returns

void

Remarks

[ API set: WordApi 1.6 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-tracked-changes.yaml

// Accepts the first tracked change.
await Word.run(async (context) => {
  const body = context.document.body;
  const trackedChanges = body.getTrackedChanges();
  const trackedChange = trackedChanges.getFirst();
  trackedChange.load();
  await context.sync();

  console.log("First tracked change:");
  console.log(trackedChange);
  trackedChange.accept();
  console.log("Accepted the first tracked change");
});

getNext()

Gets the next tracked change. Throws an ItemNotFound error if this tracked change is the last one.

getNext(): Word.TrackedChange;

Returns

Remarks

[ API set: WordApi 1.6 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-tracked-changes.yaml

// Gets the next (second) tracked change.
await Word.run(async (context) => {
  const body = context.document.body;
  const trackedChanges = body.getTrackedChanges();
  await context.sync();

  const trackedChange = trackedChanges.getFirst();
  await context.sync();

  const nextTrackedChange = trackedChange.getNext();
  await context.sync();

  nextTrackedChange.load();
  await context.sync();

  console.log(nextTrackedChange);
});

getNextOrNullObject()

Gets the next tracked change. If this tracked change is the last one, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

getNextOrNullObject(): Word.TrackedChange;

Returns

Remarks

[ API set: WordApi 1.6 ]

getRange(rangeLocation)

Gets the range of the tracked change.

getRange(rangeLocation?: Word.RangeLocation.whole | Word.RangeLocation.start | Word.RangeLocation.end | "Whole" | "Start" | "End"): Word.Range;

Parameters

rangeLocation

whole | start | end | "Whole" | "Start" | "End"

Returns

Remarks

[ API set: WordApi 1.6 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-tracked-changes.yaml

// Gets the range of the first tracked change.
await Word.run(async (context) => {
  const body = context.document.body;
  const trackedChanges = body.getTrackedChanges();
  const trackedChange = trackedChanges.getFirst();
  await context.sync();

  const range = trackedChange.getRange();
  range.load();
  await context.sync();

  console.log("range.text: " + range.text);
});

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(options?: Word.Interfaces.TrackedChangeLoadOptions): Word.TrackedChange;

Parameters

options
Word.Interfaces.TrackedChangeLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Word.TrackedChange;

Parameters

propertyNames

string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Word.TrackedChange;

Parameters

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

reject()

Rejects the tracked change.

reject(): void;

Returns

void

Remarks

[ API set: WordApi 1.6 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-tracked-changes.yaml

// Rejects the first tracked change.
await Word.run(async (context) => {
  const body = context.document.body;
  const trackedChanges = body.getTrackedChanges();
  const trackedChange = trackedChanges.getFirst();
  trackedChange.load();
  await context.sync();

  console.log("First tracked change:");
  console.log(trackedChange);
  trackedChange.reject();
  console.log("Rejected the first tracked change");
});

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Word.TrackedChange object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.TrackedChangeData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Word.Interfaces.TrackedChangeData;

Returns

track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across .sync calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you need to add the object to the tracked object collection when the object was first created. If this object is part of a collection, you should also track the parent collection.

track(): Word.TrackedChange;

Returns

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You'll need to call context.sync() before the memory release takes effect.

untrack(): Word.TrackedChange;

Returns