Please specify what version of the library you are using: [ 1.3.2 ]
Please specify what version(s) of SharePoint you are targeting: [ SPO modern framework webpart ]
Update the value of metadata fields on library documents
No errors and the request goes through with a success response. Other fields get updated, like single line of text, but not the metadata one. I've only tried single value ones. Tried both the utility function setItemMetaDataField or manually building the object.
web.lists.getByTitle("lib 2").items.getById(16).update({
"Discipline_x0020__x0028_Technical_x0029_":
{
__metadata: { "type": "SP.Taxonomy.TaxonomyFieldValue" },
Label: "Administation",
TermGuid: "54e96d6e-8390-4cac-ba3e-390a745d4f86",
WssId: -1
},
"yyy": "jj"
}
the yyy field gets updated but the metadata one doesn't. And "Administation" has the typo in the termstore too, so it's not that.
side note: the example for the single value field on this page (https://pnp.github.io/pnpjs/sp-taxonomy/docs/utilities/) has a mistake on it. It's using the function for multi value (last line).
Thanks, I've fixed the readme with setItemMetaDataField.
Regarding the issue, it doesn't look like a bug on PnPjs's side as this payload is just bypassed to the REST API ending up an ordinary HTTP call. Can it be that the field entity name is different or a field is actually configured as multi MMD value?
well I've checked field settings 100 times already and this is making no sense to me. Can't figure out why it's not working. I get the field name from the URL when you go to list settings and the click on the field:
And allow multiple values is not checked. The thing is if I write a random name it throws an error. So I assume the field name and everything is fine since I don't get an error.
Any other ideas? think it could be somehow connected to the SP modern framework environment? Any chance you could try this in a similar environment?
Can you check that the EntityPropertyName is correct (that is what is used in OData fields names, in most of the cases EntityPropertyName is the same as the internal name but not always)?
list.fields.select('InternalName,EntityPropertyName').get().then(console.log);
But, if it were an incorrect name you'd see The property 'IncorrectName' does not exist on type 'SP.Data.CustomListListItem'. Make sure to only use property names that are defined by the type., so should be something else.
Just checked on the random modern environment and single MMD fields population and update works for me with the same payload structure, the label can be even omitted at all however TermGuid must be correct otherwise The given guid does not exist in the term store error message is expected.
import { sp } from '@pnp/sp';
const list = sp.web.lists.getByTitle('CustomList');
list.items.getById(7).update({
MMDSingle: {
__metadata: { type: 'SP.Taxonomy.TaxonomyFieldValue' },
// Label: 'Department 1',
TermGuid: '220a3627-4cd3-453d-ac54-34e71483bb8a',
WssId: -1
}
})
.then(console.log)
.catch(console.log);
Out of the interest, will validateUpdateItem work?
list.items.getById(1).validateUpdateListItem([
{ FieldName: 'SingleMMDField', FieldValue: 'Department 2|220a3627-4cd3-453d-ac54-34e71483bb8a;' },
{ FieldName: 'MultiMMDField', FieldValue: 'Department 2|220a3627-4cd3-453d-ac54-34e71483bb8a;Department 3|700a1bc3-3ef6-41ba-8a10-d3054f58db4b;' }
]).then(console.log);
Appreciate it a lot that you spent the time to test in my type of environment :)
yes as you said I think there's nothing wrong with the name and actually that last suggestion you made worked!
validateUpdateListItem
Mind explaining a bit what's different between this one and the REST method? And should I just go on with this function or it's not good practice?
I can't say if it's a good or bad practice. It happens with SharePoint, something doesn't work one's need one goes another route which works.
With MMD fields, I'd suggest creating a test list/lib (oh, by the way, I've tested on a custom list but not a lib) add MMD fields and check there, probably the field was provisioned wrong way. Have no other clues actually.
UPD:
Checked on a lib, and it also works for me.
I have the exact same problem, i sent the following request via @pnp/sp:
Request 1:
let values: TypedHash
values["bshmaindepartment"] = {
Label: "Gesch盲ftsf眉hrung",
TermGuid: "88e2d10b-75ee-4004-8ec3-15c1fcead933",
WssId: -1
};
let web = new Web("");
web.lists
.getByTitle("*")
.items.getById(63)
.update(values)
.then(result => {
console.log("Finished Update");
console.log(result);
});
Request2:
let web = new Web("*");
const item = web.lists.getByTitle("*").items.getById(64);
taxonomy
.getDefaultSiteCollectionTermStore()
.getTermById("88e2d10b-75ee-4004-8ec3-15c1fcead933")
.get()
.then(term => {
setItemMetaDataField(item, "bshmaindepartment", term).then(result => {
console.log("Executed Update")
console.log(result)
});
});
Both requests didn't work, at least 98% of the time... weirdly enough, it sometimes worked, mostly right after i created the item and didn't set an initial value for this element... afterwards, it stopped working.
validateUpdateListItem did the trick, with this command i was able to update the taxonomy field. With the same testvalues i used for my other two requests.
It does seem like some kind of bug, maybe with the rest endpoint itself.
Update: Both requests always got an "Ok" Result back, never an error message.
Going to close this as answered, thanks!
Most helpful comment
Can you check that the
EntityPropertyNameis correct (that is what is used in OData fields names, in most of the cases EntityPropertyName is the same as the internal name but not always)?But, if it were an incorrect name you'd see
The property 'IncorrectName' does not exist on type 'SP.Data.CustomListListItem'. Make sure to only use property names that are defined by the type., so should be something else.Just checked on the random modern environment and single MMD fields population and update works for me with the same payload structure, the label can be even omitted at all however TermGuid must be correct otherwise
The given guid does not exist in the term storeerror message is expected.Out of the interest, will validateUpdateItem work?