Created
September 15, 2018 15:41
-
-
Save vgrem/7b9889d55dab968f971c8c04ff5758b0 to your computer and use it in GitHub Desktop.
Demonstrates how to add UserFieldValue for a Group as value in ListItem via SharePoint JSOM API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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