SP.FieldLookup.relationshipDeleteBehavior property (sp.js)

Gets or sets a value that specifies the delete behavior of the lookup field.

Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

var value = SP.FieldLookup.get_relationshipDeleteBehavior ()
var value = SP.FieldLookup.set_relationshipDeleteBehavior ()

Return value

The delete behavior. Possible values include Cascade, Restrict and None.

Exceptions

Exception Type

Condition

SPException

The field belongs to an external list.

You cannot set a value other than None if the lookup field represents a site column.

Remarks

The RelationshipDeleteBehavior property enables you enforce referential integrity in the relationship between two lists when one list depends on another list. If a lookup field in the dependent list has the RelationshipDeleteBehavior property set to Cascade, then deleting an item from the source list causes all related dependent list items to be deleted as well. For example, suppose you have a Customers list that is related to an Addresses list by a lookup field in the Addresses list. You might want deleting an item from Customers to cause all related items from Addresses to be deleted as well. You could accomplish that by setting the RelationshipDeleteBehavior property of the lookup field in the Addresses list to Cascade.

Setting the RelationshipDeleteBehavior property to Restrict prevents an item in the source list from being deleted if any items in the dependent list look up to it. For example, suppose your Customers list is the source for a lookup field in the Pending Orders list. You might not want an item from the Customers list to be deleted if the customer has pending orders. In that case, you could set the RelationshipDeleteBehavior property for the lookup field in Pending Orders to Restrict.

A lookup field that enforces a deletion constraint must be indexed. Before setting the RelationshipDeleteBehavior property to Cascade or Restrict, first set the SPFieldLookup.Indexed property to true.

Important

The user must have ManageLists permission on the source list in order to specify either Cascade or Restrict.

In addition, you cannot specify a deletion constraint if:

The current user must have SPBasePermissions.ManageLists permission on the target list when this property is set to Restrict.