前言
最近,需要更新列表欄位,欄位的型別是使用者和組,so寫了這麼一段程式碼
function updateUserField(){ var ctx = new SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getByTitle(`My List`); var item = list.getItemById(1);//Item Id var assignedToVal = new SP.FieldUserValue(); assignedToVal.set_lookupId(12);//User Id in the site collection item.set_item("AssignedTo",assignedToVal);//AssignedTo is a column name item.update(); ctx.executeQueryAsync( function() { console.log(`Updated`); }, function(sender,args) { console.log(`An error occurred:` + args.get_message()); } ); } ExecuteOrDelayUntilScriptLoaded(updateUserField, "sp.js");