Skip to main content
deleted 22 characters in body
Source Link

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());
}

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());
}

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");

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());
}
added 18 characters in body
Source Link

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('<Query><Where><And><Eq><FieldRef"<View><Query><Where>"+
 Name="Author"   "<And><Eq><FieldRef Name='Author' /><Value Type=”Integer”><UserID
Type=”Integer”Type='Integer'>  <UserID /><> </Value></Eq><Eq><FieldRefEq>"+
 Name="PostID"   "<Eq><FieldRef Name='PostID' /><Value 
Type="Number">'Type='Number'>" + id + '<"</Value></Eq><Eq>"+
    "</And></Where></Query>'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());
}

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('<Query><Where><And><Eq><FieldRef Name="Author" /><Value Type=”Integer”><UserID
Type=”Integer”/></Value></Eq><Eq><FieldRef Name="PostID" /><Value 
Type="Number">' + id + '</Value></Eq></And></Where></Query>');
this.collListItem = oList.getItems(camlQuery);
    
clientContext.load(collListItem);
    alert("1");
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());
}

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());
}
added 100 characters in body
Source Link

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('<Query><Where><And><Eq><FieldRef
  Name="Author" /><Value Type=”Integer”><UserID
Type="User">Firstname,Lastname<Type=”Integer”/></Value></Eq><Eq><FieldRef Name="PostID" /><Value 
Type="Number">id<Type="Number">' + id + '</Value></Eq></And></Where></Query>');
this.collListItem = oList.getItems(camlQuery);
    
clientContext.load(collListItem);
    alert("1");
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());
}

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.

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('<Query><Where><And><Eq><FieldRef
 Name="Author" /><Value
Type="User">Firstname,Lastname</Value></Eq><Eq><FieldRef Name="PostID" /><Value
Type="Number">id</Value></Eq></And></Where></Query>');
this.collListItem = oList.getItems(camlQuery);
    
clientContext.load(collListItem);
    alert("1");
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());
}

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('<Query><Where><And><Eq><FieldRef Name="Author" /><Value Type=”Integer”><UserID
Type=”Integer”/></Value></Eq><Eq><FieldRef Name="PostID" /><Value 
Type="Number">' + id + '</Value></Eq></And></Where></Query>');
this.collListItem = oList.getItems(camlQuery);
    
clientContext.load(collListItem);
    alert("1");
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());
}
added 14 characters in body
Source Link
Loading
added 1481 characters in body
Source Link
Loading
Source Link
Loading