Quantcast
Viewing all articles
Browse latest Browse all 6517

New Post: GetListItems and Update List Items

I know I was looking for a long time on how to get data from one list to another so I thought I might post what ended up working for me. I used two functions one to grab all of the data and the other to create new items in the second list. I know this probably is not the best way I could have accomplished my task since I am pretty new to JavaScript, but it works for my purpose and I hope it can help someone else.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 

<script language="javascript" type="text/javascript" src="/SiteCollectionDocuments/jquery.SPServices-2014.01.min.js"></script>

<script language="javascript" type="text/javascript">

function Main() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Shelter Status",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        CreateNewItem($(this).attr("ows_Title"),$(this).attr("ows_Type_x0020_of_x0020_Shelter"),$(this).attr("ows_Street_x0020_Address"),$(this).attr("ows_City"),$(this).attr("ows_Zip_x0020_Code"),$(this).attr("ows_Total_x0020_Shelter_x0020_Capaci"));
      });
      alert("Complete");
    }
  });
}


function CreateNewItem(ShelterName, TypeofShelter, ShelterAddress, ShelterCity, ShelterZipCode, TotalShelterCapacity ) {
    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "New",
        listName: "TestShelterStatus",
        valuepairs: [["Title", ShelterName],["Type_x0020_of_x0020_Shelter", TypeofShelter],["Street_x0020_Address",ShelterAddress],["City",ShelterCity],["Zip_x0020_Code",ShelterZipCode],["Total_x0020_Shelter_x0020_Capaci",TotalShelterCapacity],["Citizens","0"]],
        completefunc: function(xData, Status) {
       //   alert(TypeofShelter);
        }
    });
}

</script>
<br/>
<input id="Button" type="button" value="Click To Copy to Event" onclick="Main();" />
<p> After clicking button, Please wait for the Complete Message</p>

Viewing all articles
Browse latest Browse all 6517

Trending Articles