Class Lists
Lists SharePoint Example
The Groovy script example below illustrates using the Lists
service to create an List
SharePoint web
service object. In this examples configuration Service Parameters are accessed via the serviceParameters
map object.
import com.avoka.component.sharepoint.SPClient import com.avoka.component.sharepoint.service.Lists import com.avoka.component.sharepoint.type.RowData // Create a SharePoint client using the Service Parameters map with the configured connection details def spClient = new SPClient(serviceParameters) // Create a List web service def listService = spClient.getLists() // Get a List collection map def listItemRowData = listService.getListItems(serviceParameters.siteContext, serviceParameters.listName) // Iterate through rows Listinvalid input: '<'Map<String, String>> rowList = listItemRowData.getRowList() Iterator rowListIter = rowList.iterator() while (rowListIter.hasNext()) { Mapinvalid input: '<'String, String> rowMap = (Mapinvalid input: '<'String, String>) rowListIter.next() SetrowKeySet = rowMap.keySet() Iterator rowKeyIter = rowKeySet.iterator() while (rowKeyIter.hasNext()) { def name = (String) rowKeyIter.next() def value = rowMap.get(name) // Use name, value } }
- Since:
- 3.5.0
-
Constructor Summary
ConstructorDescriptionLists
(SPConnection sharePointConnection) Instantiate the Lists Interface wrapper with SharePoint Connection context -
Method Summary
Modifier and TypeMethodDescriptionaddAttachment
(String siteContext, String listName, String listItemId, String fileName, byte[] attachment) Adds an attachment to the specified list item in the specified list.void
checkInFile
(String pageUrl, String comment, String checkinType) Check a file into SharePoint from a remote URL.getListCollection
(String siteContext) Get all Lists within a specified Site.getListItems
(String siteContext, String listName) Get information on a List's Items.Return the web service name.updateListItems
(String siteContext, String listName, String updateXml) Adds, deletes, or updates the specified Items in a List on the specified site.Methods inherited from class com.avoka.component.sharepoint.AbstractService
buildAttributeMap, getByteStream, getDocumentElement, getDocumentTagValue, getRequestMessage, getSPConnection, getWsdlUrl, loadProperty, postMessage, postMessage
-
Constructor Details
-
Method Details
-
getServiceName
Return the web service name.- Specified by:
getServiceName
in classAbstractService
- Returns:
- the web service name
-
getListItems
Get information on a List's Items.Groovy Example
The Groovy script example below illustrates using the
Lists
service to create anList
SharePoint web service object. In this examples configuration Service Parameters are accessed via theserviceParameters
map object.import com.avoka.component.sharepoint.SPClient import com.avoka.component.sharepoint.service.Lists import com.avoka.component.sharepoint.type.RowData // Create a SharePoint client using the service parameters map with the configured connection details def spClient = new SPClient(serviceParameters) // Create a List web service def listService = spClient.getLists() // Get a List collection map def listItemRowData = listService.getListItems(serviceParameters.siteContext, serviceParameters.listName) // Iterate through rows Listinvalid input: '<'Map<String, String>> rowList = listItemRowData.getRowList() Iterator rowListIter = rowList.iterator() while (rowListIter.hasNext()) { Mapinvalid input: '<'String, String> rowMap = (Mapinvalid input: '<'String, String>) rowListIter.next() Set
rowKeySet = rowMap.keySet() Iterator rowKeyIter = rowKeySet.iterator() while (rowKeyIter.hasNext()) { def name = (String) rowKeyIter.next() def value = rowMap.get(name) // Use name, value } } Web Service Method
The Microsoft SharePoint Web Service SOAP Method:
http://schemas.microsoft.com/sharepoint/soap/GetListItems
The MSDN Method Reference:
http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems.aspx
- Parameters:
siteContext
- Provide SharePoint Site context if accessing a non-default site (Optional).listName
- Either the name or the Id for the List. Id must be surrounded by curly braces.- Returns:
- Row Data representing the SharePoint listitems fragment.
- Throws:
SPException
- in case of SharePoint error response
-
getListCollection
Get all Lists within a specified Site.Groovy Example
The Groovy script example below illustrates using the
Lists
object to create anList
SharePoint web service object. In this examples configuration Service Parameters are accessed via theserviceParameters
map object.import com.avoka.component.sharepoint.SPClient import com.avoka.component.sharepoint.service.Lists // Create a SharePoint client using the service parameters map with the configured connection details def spClient = new SPClient(serviceParameters) // Create a List web service def listService = spClient.getLists() // Get a List collection map def collectionMap = listService.getListCollection(serviceParameters.siteContext) // Iterate through collection map Iterator attrKeyIter = collectionMap.keySet().iterator(); while (attrKeyIter.hasNext()) { def listId = (String) attrKeyIter.next() def listTitle = collectionMap.get(listId) // Use list id, title }
Web Service Method
The Microsoft SharePoint Web Service SOAP Method:
http://schemas.microsoft.com/sharepoint/soap/GetListCollection
The MSDN Method Reference:
http://msdn.microsoft.com/en-us/library/lists.lists.getlistcollection.aspx
- Parameters:
siteContext
- (Optional) Provide SharePoint Site context if accessing a non-default site.- Returns:
- Mapinvalid input: '<'String,String> representing pairs of the List's invalid input: '<'Id, Title>
- Throws:
SPException
- in case of SharePoint error response
-
updateListItems
public RowData updateListItems(String siteContext, String listName, String updateXml) throws SPException Adds, deletes, or updates the specified Items in a List on the specified site. An Update XML Fragment must be provided, as per the original SharePoint Interface (Refer to MSDN).An example XML Fragment creates a new item;
<Batch OnError="Continue" ListVersion="1" ViewName="270C0508-A54F-4387-8AD0-49686D685EB2"> <Method ID="1" Cmd="New"> <Field Name='ID'>New</Field> <Field Name="Title">Value</Field> </Method> </Batch>
Groovy Example
The Groovy script example below illustrates using the
Lists
service to update a SharePoint List's Items. In this example the List Item configuration parameters are accessed via theserviceParameters
map object. TheupdateListItems
method returns aRowData
object containing added/updated/deleted item details. Eg: Use the loop algorithm in the example to check for generated ID numbers of new added items.import com.avoka.component.sharepoint.SPClient import com.avoka.component.sharepoint.service.Lists // Create a SharePoint client using the service params map with the configured connection details def spClient = new SPClient(serviceParameters) // Create a List web service def listService = spClient.getLists() // Update a List's Items. def updatedRowData = listService.updateListItems(serviceParameters.siteContext, serviceParameters.listName, serviceParameters.updateXml) // Iterate through added/updated/deleted rows in the method call result Listinvalid input: '<'Map<String, String>> rowList = updatedRowData.getRowList() Iterator rowListIter = rowList.iterator() while (rowListIter.hasNext()) { Mapinvalid input: '<'String, String> rowMap = (Mapinvalid input: '<'String, String>) rowListIter.next() Set
rowKeySet = rowMap.keySet() Iterator rowKeyIter = rowKeySet.iterator() while (rowKeyIter.hasNext()) { def name = (String) rowKeyIter.next() def value = rowMap.get(name) // Use name, value } } Web Service Method
The Microsoft SharePoint Web Service SOAP Method:
http://schemas.microsoft.com/sharepoint/soap/UpdateListItems
The MSDN Method Reference:
http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems.aspx
- Parameters:
siteContext
- (Optional) Provide SharePoint Site context if accessing a non-default site.listName
- Either the name or the Id for the List. Id must be surrounded by curly braces.updateXml
- A Batch XML Element containing add, modify or delete items as per the SharePoint Interface.- Returns:
RowData
representing the operation result as per the SharePointResults
Interface.- Throws:
SPException
- in case of SharePoint error response
-
checkInFile
Check a file into SharePoint from a remote URL.Groovy Example
The Groovy script example below illustrates using the
Lists
object to check a file into SharePoint using a remote URL. In this example the check in file parameters are accessed via theserviceParameters
map object.import com.avoka.component.sharepoint.SPClient import com.avoka.component.sharepoint.service.Lists // Create a SharePoint client using the service parameters map with the configured connection details def spClient = new SPClient(serviceParameters) // Create a List web service def listService = spClient.getLists() // Check in file listService.checkInFile(serviceParameters.pageUrl, serviceParameters.comment, serviceParameters.checkinType)
Web Service Method
The Microsoft SharePoint Web Service SOAP Method:
http://schemas.microsoft.com/sharepoint/soap/checkInFile
http://msdn.microsoft.com/en-us/library/lists.lists.checkinfile.aspx
- Parameters:
pageUrl
- Absolute URL of the document to be checked in.comment
- Check-in comments.checkinType
- 0 = MinorCheckIn, 1 = MajorCheckIn, and 2 = OverwriteCheckIn.- Throws:
SPException
- in case of SharePoint error response
-
addAttachment
public String addAttachment(String siteContext, String listName, String listItemId, String fileName, byte[] attachment) throws SPException Adds an attachment to the specified list item in the specified list.Groovy Example
The Groovy script example below illustrates using the
Lists
object to create a new List Item and adding an attachment to it.import com.avoka.component.sharepoint.SPClient import com.avoka.component.sharepoint.service.Lists // Create a SharePoint client using the service params map with the configured connection details def spClient = new SPClient(serviceParameters) // Create a List web service def listService = spClient.getLists() // Create a new List Item def updatedRowData = listService.updateListItems(serviceParameters.siteContext, serviceParameters.listName, serviceParameters.updateXml) def newListItemId = null // Iterate through rows and find the ID of the new List Item the attachment will be added to List rowList = rowData.getRowList() Iterator rowListIter = rowList.iterator() while (rowListIter.hasNext()) { def rowMap = (Map) rowListIter.next() while (rowListIter.hasNext()) { def rowMap = (Map) rowListIter.next() if (rowMap['ows_Title'] == itemTitle ){ // or use a different Item detail to identify your new added Item if there is more Items added in serviceParameters.updateXml newListItemId = rowMap['ows_ID']; } } } if (newListItemId != null ){ def attachmentUrl = listService.addAttachment(null, serviceParameters.itemListName, newListItemId, fileName, receiptPDF) }
Web Service Method
The Microsoft SharePoint Web Service SOAP Method:
http://schemas.microsoft.com/sharepoint/soap/AddAttachment
http://msdn.microsoft.com/en-us/library/lists.lists.addattachment.aspx
- Parameters:
siteContext
- Provide SharePoint Site context if accessing a non-default site (Optional).listName
- A string that contains either the title or the GUID for the list.listItemId
- A string that contains the ID of the item to which attachments are added. This value does not correspond to the index of the item within the collection of list items.fileName
- A string that contains the name of the file to add as an attachment.attachment
- A byte array that contains the file to attach- Returns:
- A string that contains the URL for the attachment, which can subsequently be used to reference the attachment or
null
if there is no result from theAddAttachment
operation call. - Throws:
SPException
- in case of SharePoint error response- Since:
- 4.1.0
-