var location = $scope.Locations[0]; console.log(location); TrafficService.getDocumentsFromDocSet(location.Location_x0020_ID) .success(function (data, status, headers, config) { data.d.results.forEach(function (item) { if (item.Name.indexOf(".zip") != -1) { //var FileName = $routeParams.RequestID + "-" + location.ID + "-" + location.CountType.replace(/\//g,'').replace(/ /g,'') + ".zip"; var FileName = location.Request_x0020_ID + "-" + location.Location_x0020_ID + "-" + location.Loc_x0020_Count_x0020_Type.replace(/\//g, "") .replace(/ /g, "") .replace(/ *\([^)]*\) */g, "") + ".zip"; var mainDomain = _spPageContextInfo.siteAbsoluteUrl.replace( _spPageContextInfo.siteServerRelativeUrl, "" ); var source = item.ServerRelativeUrl; var destination = _spPageContextInfo.webServerRelativeUrl + "/Staging Locations/" + FileName; TrafficService.copyToFileLocation(source, destination) .success(function (data2, status, headers, config) { var destination = _spPageContextInfo.webServerRelativeUrl + "/_api/web/getFileByServerRelativeUrl('/site/Traffic-Requests/Staging Locations/" + FileName + "')/ListItemAllFields"; var objProperties = { __metadata: { type: "SP.Data.Staging_x0020_LocationsItem" }, Approval_x0020_Date: new Date().toISOString(), }; TrafficService.UpdatePropertiesStagingDoc( destination, objProperties ) .success(function (data, status, headers, config) {}) .error(function (data, status, headers3, config) {}); }) .error(function (data3, status, headers, config) {}); } }); }) .error(function (data, status, headers2, config) {});