I have an RSS feed using the Google API, that pulls feed results into a page and links to them. I now want to submit the results to a SharePoint list. What's the easiest way to do this? Capture the <p> element by its ID and pass the value to a variable or textbox and submit to SharePoint? How? Also, how can I call the function for this? Basically as each new link presents on the page, send to a SP list pragmatically. The ultimate goal is a way of archiving the feed results somewhere so they can be searched.
I have two code blocks below, one for the RSS Feed, and another for submitting items to SharePoint from textbox fields.
Here is the code for the RSS Feed:
<html><head><script type="text/javascript" src="https://www.google.com/jsapi"></script><script type="text/javascript"> /* * How to find a feed based on a query. */ google.load("feeds", "1"); function OnLoad() { // Query for president feeds on cnn.com var query = 'site:news.google.com Obama'; google.feeds.findFeeds(query, findDone); } function findDone(result) { // Make sure we didn't get an error. if (!result.error) { // Get content div var content = document.getElementById('feeds'); var html = ''; // Loop through the results and print out the title of the feed and link to // the url. for (var i = 0; i < result.entries.length; i++) { var entry = result.entries[i]; html += '<p id="paragraphid"><a href=" ' + entry.link + '">' + entry.title + '</a></p>'; } feeds.innerHTML = html; } } google.setOnLoadCallback(OnLoad); $(document).ready(function(){ $('.moe').each(function(){ var content = $(this).val(); }); }); </script></head><p style="background-color:#0000E6;color:white;font-weight:bold;width:450px">Google News Feed: Obama</p><body><div id="feeds"></div></body></html>
Here is the code I'm working with for submitting items to SharePoint:
<script src="https://code.jquery.com/jquery-1.10.2.js"></script><script type="text/javascript"> var clientContext; var currentUser; var targetWeb; var text1; var text2 // When the body is loaded, the onload event handler executes each function whose name is contained in this array. _spBodyOnLoadFunctionNames.push("callCSOM"); function callCSOM() { $("#Button1").click(function() { // Make sure the SharePoint script file 'sp.js' is loaded before your code runs. text1 = $('#TextBox1').val(); text2 = $('#TextBox2').val(); ExecuteOrDelayUntilScriptLoaded(sharePointReady, "sp.js"); }); } function sharePointReady() { addListItems(); } function addListItems() { // Create an instance of the current context to return context information clientContext = SP.ClientContext.get_current(); var oList = clientContext.get_web().get_lists().getByTitle('testlist'); //Initializes a new instance of the SP.ListItemCreationInformation Class var itemCreateInfo = new SP.ListItemCreationInformation(); //Creates a new list item in the list this.newListItem = oList.addItem(itemCreateInfo); //Sets the specified field value newListItem.set_item('Title', "Title"); newListItem.set_item('TextBox1', text1); newListItem.set_item('TextBox2', text2); //Commits changed properties of the list item newListItem.update(); clientContext.load(newListItem); //Executes the current pending request asynchronously on the server clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed); } //the delegate of the method that is called when the request is executed successfully function onRequestSucceeded() { alert("Submit data successfully"); } //the delegate of the method that is called when the request is executed unsuccessfully function onRequestFailed(sender, args) { alert('Error: ' + args.get_message()); }</script><input id="Button1" type="button" value="Run Code"/><input id="TextBox1" type="text"/><input id="TextBox2" type="text"/>