|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by MrExcel1981 in JavaScript, SOAP, MS SharePoint
Hi
I am trying to add an item to a sharepoint list using javascript but I get an error. The code is below. The error I get is:
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="
http://www.w3.org/2001/XMLSchema"><
soap:Body>
<soap:Faul
t><faultco
de>soap:Se
rver</faul
tcode><fau
ltstring>E
xception of type 'Microsoft.SharePoint.Soap
Server.Soa
pServerExc
eption' was thrown.</faultstring><deta
il><errors
tring xmlns="
http://schemas.microsoft.com/sharepoint/soap/">Gu
id should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-x
xxxxxxxxxx
x).</error
string></d
etail></so
ap:Fault><
/soap:Body
></soap:En
velope>
I am pulling my hair out can someone please help! The list only has a title field.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<body>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script>
$(document).ready(function() {
$("#newTaskButton").click(function() {
CreateNewItem($("#newTaskTitle").val());
});
});
function CreateNewItem(title) {
// The CAML to create a new item and set the Title field.
var batch =
"<Batch OnError=\"Continue\"> \
<Method ID=\"1\" Cmd=\"New\"> \
<Field Name=\"Title\">" + title + "</Field> \
</Method> \
</Batch>";
// The SOAP Envelope
var soapEnv =
"<?xml version=\"1.0\" encoding=\"utf-8\"?> \
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> \
<soap:Body> \
<UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"> \
<listName>Test_Service</listName> \
<updates> \
" + batch + "</updates> \
</UpdateListItems> \
</soap:Body> \
</soap:Envelope>";
// Build the URL of the Lists.asmx web service.
// This is done by stripping the last two parts (/doclib/page) of the URL.
var hrefParts = window.location.href.split('/');
var wsURL = "";
for (i = 0; i < (hrefParts.length - 2); i++) {
if (i > 0)
wsURL += "/";
wsURL += hrefParts[i];
}
wsURL += "/_vti_bin/lists.asmx";
// Make the call by posting the SOAP Envelope.
$.ajax({
url: wsURL,
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction",
"http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
},
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=utf-8"
});
}
function processResult(xData, status) {
// Process the result.
$("#responseStatus").text(status);
$("#responseXML").text(xData.responseXML.xml);
}
</script>
Task Title:
<input id="newTaskTitle" type="text" />
<input id="newTaskButton" type="button" value="Create Task" />
<h5>
Response:
<label id="responseStatus">
N/A
</label>
</h5>
<p id="responseXML">
</p>
</body>
</html>
|
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625