Monday, October 28, 2013

Check dupliacte in list SharePoint ECMA Script : Client object model

Screen Shots:-

 
 Solution:-



<script type="text/ecmascript" language="ecmascript">
//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('<View><Query><Where><Eq><FieldRef Name=\'Title\' /><Value Type=\'Text\'>'+txtBoxValue+'</Value></Eq></Where></Query><RowLimit>10</RowLimit></View>');
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());
}
</script>
<input type='text' id='txtBox1'/><input type='button' value='button' onclick="javascript:runCode(document.getElementById('txtBox1').value);" />

No comments:

Post a Comment

SharePoint document metadata not updating

I faced a weird issue today, Metadata for document which has lookup column was not updating even after saving the item. There was no erro...