Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

how to update a people/group field using JavaScript code?

$
0
0

I have the following code.

I can update the title field but not the people/group field. I am not sure why the following code does not work.

The value 8 is the group id I am trying to update the field with.

Thanks for your help.

<script src="Mysite/SiteAssets/jquery-3.3.1.min.js" type="text/javascript"></script>
<script type="text/javascript">

 $( document ).ready(function() {
  
  
    UpdateMetaData();

}); 

function UpdateMetaData(){
  
  var listname = 'Mylist';
  alert(listname);
  var id = 1;
  
  var ProgramGroupId = 8;
 alert(ProgramGroupId);
             var ctx = SP.ClientContext.get_current();
             var oList = ctx.get_web().get_lists().getByTitle(listname);   
 
    this.oListItem = oList.getItemById(id );   
     oListItem.set_item('ProgramManager', ProgramGroupId);
 
   oListItem.update();

    ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

    alert('Item updated!');
}

function onQueryFailed(sender, args) {
   

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>                


faye fouladi


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>