Manipulating the Custom Send To Destination in document library with javascript

You all know that you can send a copy of a document from one document library to another by using the dropdown on the “Name” column and selecting “Send to > Other location”.

Some of you also know that you can add a predefined “send to location” under Document library settings > Advanced settings.

The irritating fact is that you can only add one custom location here.


Here is a method for setting this custom send to location by javascript – and being able to manipulate it for each view – or by a dropdown select.

To set the location for a view – put this code in a CEWP below the list view:

<script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
// Name displayed on the link
ctx.SendToLocationName = "My custom send to location";
// The full url to the document library to send to - i used ctx.HttpRoot as it reflects the current root
ctx.SendToLocationUrl = ctx.HttpRoot + "/TestLibrary";
</script>

IMG

To have a dropdown select, use this code:

<script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
// Define array of locations
var mySendToArr = ['<select location>|',
		 'Archive|http://www.mysendtolocation.com/Archive',
		 'Publish|http://www.mysendtolocation.com/Publish',
		 'AnotherPlace|http://www.mysendtolocation.com/AnotherPlace'];
			  	   
// Build the dropdown			  	   
var mySelect = $("<select id='myCustomSendToSelector'></select>");
$.each(mySendToArr,function(idx,item){
	var split = item.split('|');
	var opt = $("<option></option>");	
	opt.text(split[0]);
	opt.val(split[1]);
	mySelect.append(opt);
});

// Place the dropdown
$("#onetidPageTitle").append("<div style='font-size:10px;float:right;margin-top:-15px' id='insertMySendToSelectHere'>Send to location: </div>");
$("#insertMySendToSelectHere").append(mySelect);

// Add onchange
$("#myCustomSendToSelector").change(function(){
	var SendToLocationName = $(this).find('option:selected').text();
	var SendToLocationUrl = $(this).find('option:selected').val();
	if(SendToLocationUrl!=''){
		ctx.SendToLocationName = SendToLocationName;
		ctx.SendToLocationUrl = SendToLocationUrl;
	}else{
		ctx.SendToLocationName = "";
		ctx.SendToLocationUrl = "";
	}
});
</script>

This script adds a dropdown above the view selector like this:
IMG

Ask if anything is unclear!

Regards
Alexander

19 Comments on “Manipulating the Custom Send To Destination in document library with javascript

  1. could be possible that Custom Send To Destination in document library is only available for some User? (such editing the profile or creating an specific group….

  2. Alexander,

    I love the idea here and would love to leverage it but not being a Javascript master like yourself am struggling to get it to work in SP 2010 using CEWP. The other question I had was would relative referencing work in the URL for the library (i.e. /ThisLibrary vs http://sp2010/thislibrary). The dropdown is not showing up on the page and I think it could be issues with the CSS. Thanks for your thoughts!

  3. it’s good idea but where can i paste this code ?
    second >>can i make chatting inside share point between employees
    best regards
    mukhtar ahmed zaki
    system admin

    1. Hi,
      Put the code in a Content editor web part below the list view.

      As for your second question i have no solution, sorry

      Alexander

  4. thank you very much for your support..
    there is another question .. when i open shared document in explorer view it tels me that ( your client does not support opining this list with windows explorer )
    i’m using windows 7 with IE 9 and the same message with fire fox
    best regards for you

  5. Hello Alexander,
    Would this work in Sharepoint 2007?

    And would this work for something like this situation?
    My company needs to simplify the posting of documents to Production(public) and Archives(non-public) folders. When a document is published to Production it is linked to a hard coded URL and therefore always has the same name titled (i.e. Help Desk Answers) without a version number attached. However, we need a static number attached to the document that will go to the Archive folder as well. An example would be that I create the first “Help Desk Answers” document for the month of October and then I create a second “Help Desk Answers” document in November. I need to have the Archives(non-public) folder reflect that there are two “Help Desk Answers” documents now, while the document in Production(public folder) is still called just “Help desk Answers” and is the most recent document in Production. My first thought is to some how customize the “Send To” menu but if there is a better idea out there please let me know Thanks for your help!

    1. Hi,
      This solution is not “intelligent” in any way – the only thing it does it change the send to location link. I’m afraid i do not have any solution to your request.

      Alexander

  6. I’ve been browsing online greater than 3 hours these days,
    yet I by no means found any fascinating article like yours.
    It’s beautiful value enough for me. In my view, if all web owners and bloggers made
    just right content as you did, the internet will likely be
    much more useful than ever before.

  7. Whаt’s Happening i’m nnew to this, I stumbled upon this
    I’ve found It absolutely helpful and it haѕ helpеd me out loads.
    I’m hoping to give a contribution & help
    different customrs like іits heelped me. Great job.

  8. Hello, great article!

    Is there a way to use the Send To feature to create a link to of the document to another list, rather than the Send To creating another copy of the document?

    Rather than make a copy and upload the copy of document to the other library, it should be possible to create a ‘symbolic link’ via the Send To feature and get prompts should there be updates, etc to the original.

  9. Good afternoon Alexander,
    Would this work for SharePoint 2013 or would the Send To ID now have changed? Thank you for any assistance you are able to provide.

  10. Hi Alexander,

    fantastic post! but the dropdown select script does not work for me, nothing displayed at the view All document area, there are two CEPWs in the same page ( one is for hiding the Quick Lunch bar), does it matter?

  11. Hi,
    Try bringing up the developer console (hit F12 > Console) to see if you see any errors there – and please note that this article is more than 6 years old so I cannot guarantee it will still work.

    Please note that you must not load jquery more than one time in a page – if you have jquery in both CEWP’s – remove it from the second one.

    Alexander

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.