2012-06-26 3 views
0

내 모든 선택한 목록 항목을 다른 (사용자 지정) 목록으로 복사하는 스크립트가 필요합니다. 내가 정상 목록 항목에 대한 작업을 진행하게 변경해야 할 무엇인지 잘 모릅니다선택한 목록 항목을 ECMA 스크립트로 다른 목록에 복사

var context = SP.ClientContext.get_current(); 
var web = context.get_web(); 
context.load(web); 

var _destinationlib = web.get_lists().getByTitle('DestinationLibrary'); 
context.load(_destinationlib); 
var notifyId; 
var currentlibid = SP.ListOperation.Selection.getSelectedList(); 

var currentLib = web.get_lists().getById(currentlibid); 

var selectedItems = SP.ListOperation.Selection.getSelectedItems(context); 
var count = CountDictionary(selectedItems); 

for(var i in selectedItems) 
{ 
alert('Now copying ' + i); 
var currentItem = currentLib.getItemById(selectedItems[i].id); 
context.load(currentItem); 

var File = currentItem.get_file(); 
context.load(File); 

//Excecuting executeQueryAsync to get the loaded values 
context.executeQueryAsync 
(
function (sender, args) { 
if(File != null) { 

var _destinationlibUrl = web.get_serverRelativeUrl() + _destinationlib.get_title() + '/' + File.get_name(); 

File.copyTo(_destinationlibUrl, true); 
notifyId = SP.UI.Notify.addNotification('Moving file…' + File.get_serverRelativeUrl() + 'to' + _destinationlibUrl, true); 

//Excecuting executeQueryAsync to copy the file 
context.executeQueryAsync(
function (sender, args) { 
SP.UI.Notify.removeNotification(notifyId); 

SP.UI.Notify.addNotification('File copied successfully', false); 
}, 
function (sender, args) { 
SP.UI.Notify.addNotification('Error copying file', false); 
SP.UI.Notify.removeNotification(notifyId); 
showError(args.get_message()); 
}); 
} 
}, 
function (sender, args) { 
alert('Error occured' + args.get_message()); 
} 
); 
} 

: 나는 문서에 대한 좋은 해결책을 발견했다. 나는

var title = currentItem.get_Title(); 
context.load(title); 

var number = currentItem.get_item('number'); 
context.load(number); 

var File = currentItem.get_file(); 

context.load(File); 

를 교환하기 위해 노력하지만, 작품을 dosnt. 누군가가 내게해야 할 힌트를 줄 수 있다면 좋을 것입니다.

많은 들으

Fabulus

답변

1

당신이 here에서 위의 코드를했다하는 것 같습니다.

주의를 기울여보십시오. 이 코드는 목록 항목이 아닌 선택한 파일을 다른 문서 라이브러리로 복사합니다!

필요에 따라 직접 솔루션을 코딩하십시오. 자세한 내용은 SharePoint JavaScript Class Library을 참조하십시오. 가능한 아키텍처는 두 가지입니다.

  1. JavaScript로 작업 할 수 있습니다. 첫 번째 단계는 addItem method of SP.List입니다.
  2. 자바 스크립트로 클라이언트에서 선택 처리를하고 항목 복사 (초기 목록에서 이미 존재하는 항목의 새 목록에 사본 만들기)를 위해 사용자 지정 서버 측 구성 요소 (응용 프로그램 페이지 일 수 있음)를 호출하십시오. 예를 들어 this을 참조하십시오.

또한 context.load와주의하십시오. 다음 코드를 모두 context.executeQueryAsync에 작성하는 것이 좋습니다. 코드를 디버깅하고 잘못된 것을 찾으려면 Chrome의 FF 및 개발자 도구에서 Firebug를 사용하십시오.

관련 문제