replaceReferences( )


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

Replaces current references with references in the specified property.

The replaceReferences() method returns a Promise that resolves when the item's current references in the specified property are removed and references to the referenced items are added in their place. The Promise is rejected if the current user does not have update permissions for the collection.

Note: The replaceReferences() method is not supported for single-item collections.

Permissions
Write Data Items
Learn more about app permissions.
Method Declaration
Copy
function replaceReferences(
  dataCollectionId: string,
  field: string,
  referringItem: union,
  referencedItem: union,
  options: WixDataOptions,
): Promise<void>;
Method Parameters
dataCollectionIdstringRequired

ID of the collection that contains the referring item.


fieldstringRequired

Field to replaces the references in.


referringItemunionRequired

Referring item or referring item's ID.


referencedItemunionRequired

Referenced item, referenced item's ID, an array of referenced items, or an array of referenced item IDs.


optionsWixDataOptions

Options to use when processing this operation.

This example replaces the references in the Actors field of the item in the Movies collection with the ID 00001 with a reference to the item with ID 12345.

JavaScript
import { items } from "@wix/data"; async function replaceItemReferences() { await items.replaceReferences("movies", "actors", "00001", "12345"); console.log("References replaced"); }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?