0

I have a newrequest.aspx page in a Sharepoint 2013 App with a form on it to get details from my users to submit a leave request,this is then submitted to a Sharepoint list to hold all of the requests for a workflow. On this form I have created a peoplepicker using the following code:

<script type="text/javascript">
    $(document).ready(function () {
        $("#manager").spPeoplePicker();
     });
</script>

Then in my .js file I have the following code to retrieve the values from that peoplepicker :

   var managerTitle = $("#manager_TopSpan_ResolvedList").find("span.ms-entity-resolved").attr("title");

Then I have the following code in the same .js file to submit these values to my list using javascript/ecmascript.(Note, I am only copying relevant code here, This all is part of a leave request app that I am busy with,so there is more fields in use but they all work fine)

Code:

var oList = context.get_web().get_lists().getByTitle("Leave Requests");
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item("Manager", managerTitle);
oListItem.update();
context.load(oListItem);
context.executeQueryAsync(Function.createDelegate(this,       this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

The manager field chosen above is also a peoplepicker. I am looking for assistance to set that value. The code above gives an error by saying

Invalid data was used to update the field or the field may be read-only

I have googled and tried a lot of different recommendations to no avail. Any assistance will be appreciated.

3

Use oListItem.set_item("Manager", SP.FieldUserValue.fromUser(managerTitle)); to set the person type field.

  • This is the exact answer that I was looking for! Thank you Sir! So simple. Just one thing, Remove the quotes around managerTitle. – Memphis335 Oct 1 '15 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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