DispForm Button to Append People Picker with Current User

Forums Dynamic Forms for SharePoint DispForm Button to Append People Picker with Current User

Viewing 1 reply thread
  • Author
    Posts
    • #14597
      Celeste Garcia
      Participant

      I have a requirement to allow users to add their name to a multi people picker field by clicking a button in DispForm. Is this possible? I have tried several approaches and cannot find a way to update a record form DispForm….

    • #14606
      Alexander Bautz
      Keymaster

      Hi,
      You can add this code to the Custom JS in your DispForm:

      function addMeToPP(){
          var item, currPP, newPP, uItem;
          item = spjs.utility.getItemByID({"listName":_spPageContextInfo.pageListId,"id":spjs.dffs.data.thisItemID,"viewFields":["PeoplePicker2"]});
          currPP = item.PeoplePicker2;
          if(currPP.indexOf(_spPageContextInfo.userId+";#") === 0 || currPP.indexOf(";#"+_spPageContextInfo.userId+";#") > -1){
              alert("Your have already been added to this field.");
          }else{
              newPP = currPP+";#"+_spPageContextInfo.userId+";#";
              uItem = spjs.utility.updateItem({"listName":_spPageContextInfo.pageListId,"id":spjs.dffs.data.thisItemID,"data":{"PeoplePicker2":newPP}});
              if(uItem.success){
                  location.reload();
              }else{
                  alert(uItem.errorText);
              }
          }
      }

      You must change “PeoplePicker2” with the field internal name of your field.

      Then add this code to a “HTML section” in one of your tabs:

      <input type="button" value="Add me to the PP" onclick="addMeToPP()" />

      Let me know how this works out.

      Alexander

Viewing 1 reply thread
  • You must be logged in to reply to this topic.