0

I just created a custom edit form for a list in SP Designer from a task list, i created 3 more taskoutcome options and a button for each option, one of them only edit the assigned to field and update the list for CSOM, the problem is that I couldnt get the user ID for the person picker with JavaScript to send an update to the task list.

In dev tools all the info appear in a div with a data attributte ArrayOfDictionaryEntry where the user id appears, I just tried to retrieve it like this:

//only dataset because is <div data="info">
getElementsByTagName("DIV").dataset

how can I get the user id from the person picker to send an update to list?

1 Answer 1

-1

I found the answer, gettin the attribute description on div#divEntityData that return the info domain\user and sending to currentUser.get_id(); as bellow

function getUser(user){
      var clientContext = new SP.ClientContext.get_current();
    var website = clientContext.get_web();
    currentUser = website.ensureUser(user);
    clientContext.load(website);
    clientContext.load(currentUser);
    clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
}


    function onRequestSucceeded() {
       var userid =  currentUser.get_id();

finally the userid send to update the assignedTo field like this

function updateItem(taskoutcome,idUser) {
   var clientContext = new SP.ClientContext.get_current();
   var oList = clientContext.get_web().get_lists().getByTitle('TaskList');
   this.oListItem = oList.getItemById(QueryString.ID);
   oListItem.set_item('TaskOutcome', taskoutcome);
   oListItem.set_item('AssignedTo', idUser);

   oListItem.update();              
   clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.