What I am trying to achieve is using javascript to check if a user has created an item for the post. So it would check if post ID = current post and created by = current user.
If it finds an item exists then it is to exit.
If item does not exists then I have another function I need to run to create the item.
The issue seems to be it's getting up to excutequeryasync then nothing is happening
Currently I have the following code.
function createListItem(decision, id, likes) {
var siteUrl = '/';
var countLikes = likes;
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('PostLikes');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><Where>"+
"<And><Eq><FieldRef Name='Author' /><Value Type='Integer'> <UserID /> </Value></Eq>"+
"<Eq><FieldRef Name='PostID' /><Value Type='Number'>" + id + "</Value></Eq>"+
"</And></Where></Query></View>");
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
alert("1");
alert(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
alert("2");
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nID: ' + oListItem.get_id() +
'\nTitle: ' + oListItem.get_item('PostID') +
'\nBody: ' + oListItem.get_item('Like');
}
alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}