0

I have requirement which is

  1. Retrieve List Items in a List(list created through OOB)
  2. Display those list items on the sharepoint site by binding to repeator control
  3. Using javascript and client object model.

Steps I have done

  1. Created a new SharePoint Project
  2. Added a new Application Page to the project
  3. Wrote the below code

<script type="text/javascript">
    var ListItem;
    function GetListItems(listname, listItemId)
    {
        var SPContext = new SP.ClientContext.get_current();
        var web=SPContext.get_web();

        var List=web.get_lists().getByTitle("Menu Items");
        ListItem = list.getItemById(listItemId);

        SPContext.load(ListItem,"Menu_Title","Menu_Image","Menu_Description");
        SPContext.executeQueryAsync(GetListItemById);
    }
    function GetListItemById_Successor(sender, args)
    {
        var id = ListItem.get_id();
        var title = ListItem.get_item("Menu_Title");
        var Image = ListItem.get_item("Menu_Image");
        var Description = ListItem.get_item("Menu_Description");
        alert("Updated List Item: \n Id: " + id + " \n Title: " + title+ "\n Image:" +Image+ "\n Description:" +Description );
    }
    function GetListItemById_Fail(sender, args)
    {
        alert("GetListItemById Failed. \n" + args.get_message() + "\n" + args.get_stackTrace());
    }
</script>

My code deploys successfully with no errors but not able to see... Please help me on this,I am not getting an intellisense menu for the client object model classes and objects.

Is there a step by step process tutorial or suggestions are highly appreciated

Retreving items in a SharePoint list using Client Object Model in javascript and bind that to repeator control

  • executeQueryAsync() should contain success and fail callbacks both. example: executeQueryAsync(GetListItemById_Successor, GetListItemById_Fail); – Garima Jan 8 '14 at 10:13
1

instead of:

SPContext.executeQueryAsync(GetListItemById);

do:

SPContext.executeQueryAsync(Function.createDelegate(this, this.GetListItemById_Successor), Function.createDelegate(this, this.GetListItemById_Fail));        

http://msdn.microsoft.com/en-us/library/hh185007(v=office.14).aspx

  • Why do we need to call Function.createDelegate() ? – Florian Leitgeb Jun 29 '15 at 11:35
  • thats because it needs to pass the values to the function. Function.createDelegate means your creating a function and within the function your delegating varibles to that function. in the example above its calling: " function onQuerySucceeded(sender, args) { " and " function onQueryFailed(sender, args) { " both are functions and both have two paramaters that i delegated to it. – Ali Jafer Jun 29 '15 at 14:31
  • Ah thank you. So I can take your first line of code if I do not need to delegate arguments and if I need some I use the createDelegate. But unless of delegating variables it should be the same. Am I right? – Florian Leitgeb Jun 30 '15 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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