0

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>

2 Answers 2

0

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?

4
  • 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. Commented Mar 7, 2012 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.". Commented Mar 7, 2012 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. Commented Mar 8, 2012 at 4:05
  • That was the problem. I recreated the fields and it's working great now. Thank you for your help! Commented Mar 8, 2012 at 18:49
0

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

3
  • 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). Commented Mar 6, 2012 at 20:26
  • have you tried anything so far ? Commented Mar 7, 2012 at 7:33
  • I've added the code I've been working with. Thanks! Commented Mar 7, 2012 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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