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

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

EDIT:

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(); 

  myQuery.set_viewXml(myQueryString);
  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"); 

  } 
  alert(ExampleItemsDetails); 
  SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
} 
</script> 

Appreciate any help.

share|improve this question
    
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 '12 at 16:19

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 '12 at 16:34

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.