Sub fonctionne en VBA, pas en VBS
Bonjour,
J'ai codé une procédure pour écrire dans une liste d'un sharepoint mais j'aimerai la lancer en parallèle d'autres traitemets. Il me faut donc la place dans un VBS sauf que je dois faire quelquechose de faux car les changements n'aparaissent pas une fois le script exécuté (sans erreurs, depuis la cmd).
Voyez vous ce qui cloche dans mon code?
VBA:
Code:
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
| Sub Add_Item_SP(ListGUID As String, SharepointUrl As String, ValueID As String, ValueNC As String, _
ValueIN_Date As String, ValueIN_Time As String, ValueOUT_Date As String, ValueOUT_Time As String, _
ValueAction As String, ValueLast_Agent As String, ValueLoop As String, ValueMSN As String, _
ValueTechnical_Status As String, ValueCA_Code As String, ValueCluster As String, ValueLeadtime As String)
'For this code to works, add references to VBA: Microsoft XML, v6.0
Dim objXMLHTTP As MSXML2.XMLHTTP
Dim strListNameOrGuid As String
Dim strBatchXml As String
Dim strSoapBody As String
'Create HTTP Object
Set objXMLHTTP = New MSXML2.XMLHTTP
'Prepare SOAP Request content (columns and values to be added)
strBatchXml = _
"<updates>" & _
"<Batch OnError=""Continue"" ListVersion=""1"">" & _
"<Method ID=""1"" Cmd=""New"">" & _
"<Field Name='ID'>New</Field>" & _
"<Field Name=""ID0"">" & ValueID & "</Field>" & _
"</Method>" & _
"</Batch>" & _
"</updates>"
'Set SOAP/Webservice Parameters
objXMLHTTP.Open "POST", SharepointUrl + "_vti_bin/Lists.asmx", False
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
objXMLHTTP.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
'Set SOAP Envelope
strSoapBody = _
"<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>" & ListGUID & "</listName>" & _
strBatchXml & _
"</UpdateListItems>" & _
"</soap:Body>" & _
"</soap:Envelope>"
'Send SOAP Request
objXMLHTTP.send strSoapBody
Debug.Print strSoapBody
If objXMLHTTP.Status = 200 Then
'do something with Response
'MsgBox objXMLHTTP.responseText
Else
Debug.Print objXMLHTTP.Status
End If
'Var cleaning
Set objXMLHTTP = Nothing
End Sub |
VBS:
Code:
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
| Dim objXMLHTTP
Dim strListNameOrGuid
Dim strBatchXml
Dim strSoapBody
'Create HTTP Object
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
'Prepare SOAP Request content (columns and values to be added)
strBatchXml = _
"<updates>" & _
"<Batch OnError=""Continue"" ListVersion=""1"">" & _
"<Method ID=""1"" Cmd=""New"">" & _
"<Field Name='ID'>New</Field>" & _
"<Field Name=""ID0"">" & "111000000" & "</Field>" & _
"</Method>" & _
"</Batch>" & _
"</updates>"
'Set SOAP/Webservice Parameters
objXMLHTTP.Open "POST", "https://............../_vti_bin/Lists.asmx", False
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
objXMLHTTP.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
'Set SOAP Envelope
strSoapBody = _
"<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>" & "{1321E116-94A8-4757-A4AF-57CF09C6DE59}" & "</listName>" & _
strBatchXml & _
"</UpdateListItems>" & _
"</soap:Body>" & _
"</soap:Envelope>"
'Send SOAP Request
objXMLHTTP.send strSoapBody
wscript.echo objXMLHTTP.responseText
'Var cleaning
Set objXMLHTTP = Nothing |