Check dupliacte in list SharePoint ECMA Script : Client object model

Screen Shots:-

 

 Solution:-

//Get the list item from the Announcements list whose Id is 4. Note that this is the ID of the item in the list, not a reference to its position in the collection.
var itemId = 1;
var targetListItem;
var collListItem;
function runCode(txtBoxValue) {
alert(txtBoxValue);
var clientContext = new SP.ClientContext();
var targetList = clientContext.get_web().get_lists().getByTitle(‘TestECMAList’);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(”+txtBoxValue+’10’);
collListItem = targetList.getItems(camlQuery);

//targetListItem = targetList.getItemById(itemId);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {

//alert(‘Request succeeded. \n\nRetrieved Item is: ‘ + targetListItem.get_item(‘Title’));
var listItemInfo = ”;
var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += ‘\nID: ‘ + oListItem.get_id() +
‘\nTitle: ‘ + oListItem.get_item(‘Title’) ;
}
if(listItemInfo.toString()==””)
{
alert(‘Item not found’);
}
else
{
alert(listItemInfo.toString());
}

}
function onQueryFailed(sender, args) {
alert(‘Request failed. \nError: ‘ + args.get_message() + ‘\nStackTrace: ‘ + args.get_stackTrace());
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s