0
votes

In Java, I have a connection to a Sharepoint working and it can retrieve the data in a List with no problem when I specify the internal name of the data column explicitly as below. ArrayList listHash = new ArrayList(); String viewName = ""; GetListItems.ViewFields viewFields = null; GetListItems.Query msQuery = null; GetListItems.QueryOptions queryOptions = null; String webID = ""; String rowLimit = "";

GetListItemsResponse.GetListItemsResult result = listsoap.getListItems(listName, "", msQuery, viewFields, "150", queryOptions, webID);
Object listResult = result.getContent().get(0);

Element element = (Element)result.getContent().get(0);
NodeList nl = element.getElementsByTagName("z:row");
System.out.println("\n=> " + nl.getLength() + " results from SharePoint Online\n");
for(Integer i = 0; i < nl.getLength(); i++) {

     NamedNodeMap attributes = nl.item(i).getAttributes();

     //Add each field item to the arraylist
     String columnName1 = "ows_ClientName";
     String columnName2 = "ows_Address";
     System.out.println(attributes.getNamedItem(columnName1).getNodeValue());
     System.out.println(attributes.getNamedItem(columnName2).getNodeValue());
}

But I would like to retrieve those column names automatically from the sharepoint List so I can read it more generically, and not have to specifically know what the internal names of the columns in the List are before I can read them. Can this be achieved?

Any help is appreciated.

With Regards,

1

1 Answers

0
votes

I'm assuming you're consuming SharePoint Web Services. If that's the case you can try calling the method GetList and passing the listname as a parameter to that method. The web service's result will be the schema of your list which contains details of the list including internal names of the columns. Let me know if this works.