How I created a “Copy to new item” functionality for a SharePoint list – Part 2

Second part. First Part can be found here. On the second page (NewForm.aspx), I grabbed out of the querystring the values for the source list item and the name of the list.
I used this person’s query string parser.

Then I used the following SOAP query :

$(document).ready(function() {
 var sourceID = getQuerystring('SourceID');
 var listName = getQuerystring('ListName');

 var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>" + listName + "</listName> \
<viewName>{GUID}</viewName> \
<viewFields /> \
<ViewFields /> \
<query> \
<Query><Where> \
<Eq> \
<FieldRef Name='ID' /> \
<Value Type='Integer'>" + sourceID + "</Value> \
</Eq> \
</Where></Query>\
</query> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";

 $.ajax({
 async: false,
 url: "http://site.com/subsite/_vti_bin/lists.asmx",
 type: "POST",
 dataType: "xml",
 data: soapEnv,
 complete: processResult,
 contentType: "text/xml; charset=\"utf-8\""
 });

 });
 function processResult(xData, status) {
 $(xData.responseXML).find("z\\:row").each(function() {
 $("input[title='Input']").val($(this).attr("ows_Input"));
 $("textarea[title='TextArea']").val($(this).attr("ows_TextArea"));
 $("select[title='DropDown']").val($(this).attr("ows_DropDown")).attr("selected", "selected"); 
 }
 )};

In the last three lines I changed the input box, textbox and dropdown boxes to their values in the results fromt the SOAP query.

Kinda fun. Just need to figure out how to do check boxes!

,

Comments are closed.

Powered by WordPress. Designed by WooThemes