Reputation: 21
Document Set Homepage:
I am using Angularjs and REST API to retrieve the documents on my SharePoint 2013 document set homepage for additional functionaity. The below code works if I provide the list and folder name ('AD%20Letters/Liquidity%20Risk%20Management'), but I have more then one document set folder and need to get the List and folder names dynamically ('"+ListName/FolderName+"') for each document set folder so it displays on the Document Set Home with the documents and other metadata. Attaching a screenshot of how the Document set homepage appears with the below code but only for the Liquidity Risk Management folder that I provide the names for. Any suggestions.
<script type="text/javascript">
var myAngApp = angular.module('SharePointAngApp', []);
myAngApp.controller('spCustomerController', function ($scope, $http) {
$http({
method: 'GET',
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/getfolderbyserverrelativeurl('AD%20Letters/Liquidity%20Risk%20Management')/files?$expand=ListItemAllFields/FieldValuesAsText
}).success(function (data, status, headers, config) {
$scope.customers = data.d.results;
}).error(function (data, status, headers, config) {
});
});
</script>
<h1> Policy Documents</h1>
<div ng-app="SharePointAngApp" class="row">
<div ng-controller="spCustomerController" class="span10">
<table class="table table-condensed table-hover">
<tr>
<th>ID</th>
<th>File Type</th>
<th>Title</th>
<th>Project Phases</th>
<th>Due Date for Comments</th>
<th>Policy Type</th>
<th>Author</th>
</tr>
<tr ng-repeat="customer in customers | orderBy:'ListItemAllFields.Development_x0020_Stage'">
<td>{{customer.ListItemAllFields.ID}}</td>
<td class="{{customer.ListItemAllFields.FieldValuesAsText.File_x005f_x0020_x005f_Type}}"></td>
<td><a href="{{customer.ServerRelativeUrl}}">{{customer.Name}}</a></td>
<td>{{customer.ListItemAllFields.Development_x0020_Stage}}</td>
<td>{{customer.ListItemAllFields.FieldValuesAsText.Date_x005f_x0020_x005f_for_x005f_x0020_x005f_Review}} </td>
<td>{{customer.ListItemAllFields.Type_x0020_of_x0020_Letter}}</td>
<td>{{customer.ListItemAllFields.FieldValuesAsText.Author}} </td>
</tr>
</table>
</div>
</div>
Upvotes: 2
Views: 1198
Reputation: 21
I figured how to do this for those who might benefit. I used the available SharePoint GetUrlKeyValue
and grabbed the RootFolder
which is available as a querystring for each document set (var listFolder = GetUrlKeyValue("RootFolder");
)
var listFolder = GetUrlKeyValue("RootFolder");
var url = "/_api/web/getfolderbyserverrelativeurl('"+listFolder+"')/files?$expand=ListItemAllFields/FieldValuesAsText"
Now I get documents/files for each docset folder on the Docset Homepage.
Upvotes: 0
Reputation: 498
I believe you'd like to make parallel ajax calls and combine all the results?
var myAngApp = angular.module('SharePointAngApp', []);
myAngApp.controller('spCustomerController', function ($scope, $http) {
$q.all({
liquidityRiskManagement: $http({
method: 'GET',
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/getfolderbyserverrelativeurl('AD%20Letters/Liquidity%20Risk%20Management')/files?$expand=ListItemAllFields/FieldValuesAsText"
}),
anotherList: $http({
method: 'GET',
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/getfolderbyserverrelativeurl('AD%20Letters/Another%20List%')/files?$expand=ListItemAllFields/FieldValuesAsText"
})
}).then(function(results) {
var riskResult = results.liquidityRiskManagement.data;
var anotherResult = results.anotherList.data;
// You can combine/format data here
});
});
EDIT: a good answer on parallel ajax calls: https://stackoverflow.com/a/24871403/6479268
Upvotes: 0