Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to write a script using the Client Object Model that searches for information from a document library, but I'm having no luck. However, using the same script with a couple of variables changed, I've noticed that it works fine within a list.

I guess my question is: is it possible to manipulate library items (using the Client Object Model and ECMAScript) like you would list items?

Thanks in advance for any information you can provide!

Edit: Here is the code I'm working with (works fine within a list):

<script type = "text/javascript">
ExecuteOrDelayUntilScriptLoaded(initialize, "SP.js");

function initialize(){
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle("LibraryName");
    var query = new SP.CamlQuery();

    var queryText = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>SomeTitle</Value></Eq></Where></Query></View>";

    query.set_viewXml(queryText);

    var items = list.getItems(query);

    context.load(items);

    context.executeQueryAsync(Function.createDelegate(this, querySuccess), Function.createDelegate(this, queryFailure));

    function querySuccess(sender, args){    
        alert("Success");
    }

    function queryFailure(sender, args){
        alert("Failure");
    }
}
</script>
share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Yes you can. A Library is essentially a list and the library items are essentially list items. Can you post your code here so that we can figure out what might be going wrong?

share|improve this answer
    
My code has been added, thanks! –  Drew Papworth Mar 7 '12 at 13:12
    
Your Code looks all good.What exactly is the error which is thrown? Can you make the Failure function like this: function queryFailure(sender, args){ alert(args.get_message()); } This will give us more information about the error. –  Vardhaman Deshpande Mar 7 '12 at 17:54
    
The error that is thrown is "One or more field types are not installed properly. Go to the list settings page to delete these fields.". –  Drew Papworth Mar 7 '12 at 18:32
1  
Yup. This error occurs when there are some corrupted fields in your Document Library. Did you add any custom fields to the document library recently? If yes, you will have to delete and re-create them. Also, try to create a brand new Document library and try your code on that library. –  Vardhaman Deshpande Mar 8 '12 at 4:05
    
That was the problem. I recreated the fields and it's working great now. Thank you for your help! –  Drew Papworth Mar 8 '12 at 18:49
add comment

Yes You can.

Your code does look correct to retrive items from your document library. Judging from your error it has something to do with the configuration of your library.

what else would you like to manipulate

share|improve this answer
    
Well, the library is an InfoPath form library. There are several integer columns that receive data whenever a form is submitted. All I really need to do is search/get the item's values (to be used elsewhere for some custom reporting). –  Drew Papworth Mar 6 '12 at 20:26
    
have you tried anything so far ? –  Sebastien Stettler Mar 7 '12 at 7:33
    
I've added the code I've been working with. Thanks! –  Drew Papworth Mar 7 '12 at 13:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.