Please specify what version of the library you are using: 2.0.4
Please specify what version(s) of SharePoint you are targeting: SPO
How can you update the value of the RelationshipDeleteBehavior property on a lookup field using PnPjs?
Using the following code:
const change = {RelationshipDeleteBehavior: 1};
sp.web
.lists.getById(listGuid)
.fields.getById(fieldGuid)
.update(change);
fails with the following error:
The property 'RelationshipDeleteBehavior' does not exist on type 'SP.Field'. Make sure to only use property names that are defined by the type.
So far I wasn't able to find any reference to the RelationshipDeleteBehavior property in the repo or docs but perhaps there is another way to apply a change to a lookup field that I'm missing.
For the reference, the following REST request works as expected:
POST .../_api/web/lists('listGuid')/fields('fieldGuid')
accept: application/json
content-type: application/json
IF-MATCH: *
X-HTTP-Method: MERGE
{"@odata.type":"#SP.FieldLookup","Indexed":true,"RelationshipDeleteBehavior":1}
For fields you need to specify the field type on update which is the second parameter. I just saw that the docs don't mention this so need to update that. Your example would be:
const change = {RelationshipDeleteBehavior: 1};
sp.web
.lists.getById(listGuid)
.fields.getById(fieldGuid)
.update(change, "SP.FieldLookup");
That is how to do it today. We could make a request for the type and just set it for folks which might be easier. Originally we didn't because of the extra call for all updates. Best might be to leave the param so it isn't a breaking change but make it optional. If undefined we do a lookup for the type and use that.
Thank you for the explanation. The reasoning makes sense. Using the field type is good enough for now and it unblocks me. Thanks for your help! 👍
Made this change will go out in the next version.
@patrick-rodgers - this issue persists in v2.0.5


Most helpful comment
Made this change will go out in the next version.