New to SP dev, but recently learned how to retrieve data from lists using ECMA with CAML. Added a CEWP, wrote the script to retrieve the data and it is working fine, multiple field filters, etc. However, I searched online to learn this and there are tons of examples (helped a lot) but they all show alerts with values (which is fine).

Now I am wondering how to fill webparts with the data i have retrieved bia this method? Is there a good resource for some of the JavaScript basics such as this? Again, everything I have found thus far simply uses alerts. Thanks


Apologies if that question was unclear. So I am trying to pull data from a list on to a page through Content Editor Web Part. Added a link to call the functions below. Was trying to use this method to learn CAML so that I could add my own query/filters. I learned this basic example via multiple blogs/MSDN on the subject, so perhaps I am confused about context. Anyway the below works fine, pulling from a list I create with 'Title' and'ExampleFilterValue' > 5, but I have only thus far learned how to display the results with an alert. I use this script in the HTML editor of the CEWP.

My question is can you take an approach such as this and display the resulting values in a webpart, so can I display the values returned from the following in the same or another webpart?

<a href="javascript:getMyQueryData()">Link to Pull Data</a><script type="text/javascript">
var myItems;

function getMyQueryData() 
  var myQueryString = '<View><Query><Where><Gt><FieldRef Name="ExampleFilterValue" /><Value Type="Integer">5</Value></Gt></Where><OrderBy><FieldRef Name="Title" /></OrderBy></Query></View>'; 
  var myContext = new SP.ClientContext.get_current(); 
  var myWeb = myContext.get_web(); 
  var myList = myWeb.get_lists().getByTitle('ExampleList'); 
  var myQuery = new SP.CamlQuery(); 

  myItems = myList.getItems(myQuery);
  myContext.load(myItems, 'Include(Title, ExampleFilterValue)');
  myContext.executeQueryAsync(Function.createDelegate(this, getExampleItemsSuccess), Function.createDelegate(this, GetExampleItemsFail));  
function GetExampleItemsFail(sender, args) 
  alert('getMyQueryData() failed:' + args.get_message()); 

function getExampleItemsSuccess(sender, args) 
  var ExampleItemsEnumerator = myItems.getEnumerator();  
  var ExampleItemsDetails = '';
  while (ExampleItemsEnumerator.moveNext()) 
    var currentExampleItem = ExampleItemsEnumerator.get_current(); 
    ExampleItemsDetails = ExampleItemsDetails + '\n' + currentExampleItem.get_item("Title") + ' ' + currentExampleItem.get_item("ExampleFilterValue"); 


Appreciate any help.

  • Could you please clarify what you are doing (links to source materials, sample code, exact webpart types, whatever) as there is simply not enough here to respond to.
    – Dave Wise
    May 25, 2012 at 16:19

1 Answer 1


this is a job for jQuery. Using jQuery you can select the web part element you want to fill, and then fill it with the value you want.

So, if you had a text box with an ID of ClientName, for example, you might do something like this:

$('#ClientName').text( myItem.get_item("ClientName"));

Once you have the data, that's all there is to it.

Not sure how familiar you are with jQuery but in essence it's just a javascript file you link to.

  • Thanks for your response. I am not familiar with jQuery but I can certainly change that, which I am sure will lead to more questions. Thanks for the help!
    – Justin
    May 25, 2012 at 16:34

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.