Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demonstrates how to add UserFieldValue for a Group as value in ListItem via SharePoint JSOM API
function addListItem(list, properties) {
let ctx = list.get_context();
let itemCreateInfo = new SP.ListItemCreationInformation();
let listItem = list.addItem(itemCreateInfo);
for (let name in properties) {
listItem.set_item(name, properties[name])
}
listItem.update();
return executeQuery(ctx);
}
function executeQuery(context) {
return new Promise((resolve, reject) => {
context.executeQueryAsync(function () {
resolve();
}, function (sender, args) {
reject(args);
});
});
}
let ctx = SP.ClientContext.get_current();
let group = ctx.get_web().get_associatedMemberGroup();
ctx.load(group);
executeQuery(ctx)
.then(() => {
let groupVal = new SP.FieldUserValue();
groupVal.set_lookupId(group.get_id());
let list = ctx.get_web().get_lists().getByTitle("Tasks");
let taskProps = {
"Title": "Task123",
"AssignedTo": groupVal
}
return addListItem(list,taskProps);
})
.then(() => {
console.log("Saved");
})
.catch((sender,args) => {
console.log(args.get_message());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment