I'm trying to just Javascript to add a list item when in SharePoint 2013 using the following code;
function createListItem(var lookup_Value) {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('CrewNoticesAudit');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', 'My New Item!');
oListItem.set_item('NoticeId', lookup_Value); // THIS IS A LOOKUP VALUE
oListItem.set_item('User', 'administrator');
oListItem.set_item('TimeStamp', new Date());
oListItem.set_item('AuditType', 'Open');
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert('Item created: ' + oListItem.get_id());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
The problem is that I'm getting one error "The field you are trying to update maybe read only" when I'm trying to run this code, I need to get the ID from the lookup list instead of the lookup value, is there a way to get the ID from a list with just the lookup value?