I want to add a list element via JavaScript which works (almost).
After the help from a user here I got this
function fillStandard() {
console.log("Standard");
var posInvest = "Invest";
var posRecipient = accResponsible;
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Position');
var item = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(item);
oListItem.set_item('PosType', posInvest);
oListItem.set_item('Recipient', posRecipient);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
console.log("successfully executed");
}
function onQueryFailed(sender, args) {
console.log("failed");
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
If I outcomment oListItem.set_item('Recipient', posRecipient); it works.
The problem is that I have defined accResponsible as
var accResponsible = "[{\"email\":\"[email protected]\",\"id\":\"i:0#.w|opmain\\\\eojdoe\",\"label\":\"John, Doe\",\"title\":\"\",\"type\":\"User\",\"value\":\"i:0#.w|opmain\\\\eojdoe\"}]";
which gives an error (invalid data has been used to update the field)
The field should normally get the value of a user (peoplePicker), for example something like this
posRecipient = NWF$("#" +varManager1).val(accResponsible);
But when I do that, the field remains blank. Does someone know how to solve this?
