Multiple pages item selection...

Nov 25, 2011 at 3:07 AM

Hi there..

Your solution worked like a charm.. 

The current solution is gr8 for current page...

But is it possible to select the items via multiple pages and then add  them as attachment...

 

 

Coordinator
Nov 25, 2011 at 6:25 AM

Hi, thanks. Selecting the items via multiple pages isn't in the scope of this feature. But I will note it on our feature wish list...

Nov 30, 2011 at 5:07 AM

Thanks for your reply....

I tried to create the solution using cookies using your JavaScript code. 

It works fine but the ExecuteQueryAsync sometimes returns '12002' status error code..

[I am using using jquery - when document gets ready method and checking the ($(".s4-itm-cbx").is(":checked")) on $(".s4-itm-cbx").click(function ()  ]

Ane idea what can be wrong??

to test add a content editor webpart to ant Sharepoint library - Allitem.aspx  click the button..

<input name="button1" onclick="getOutlook(); return true" type="button" value="Add as Attachment"/><script type="text/javascript">var item;var web;var site;var sdList;var clientContext;
$(document).ready(function () {//alert("script added"); $(".s4-itm-cbx").click(function () {
        // If checked        if ($(".s4-itm-cbx").is(":checked")) {
try {      AddSelectedItemCookie(parseInt(this.title)); //alert(this.title);   
}    catch (e) {        alert(e);    }
         }
        else { try {              RemoveUnSelectedItemcookie(parseInt(this.title)); //alert(this.title); }    catch (e) {        alert(e);    }         }    });

});

function AddSelectedItemCookie(itemID){ clientContext = SP.ClientContext.get_current();    web =  clientContext.get_web(); site = clientContext.get_site(); sdList =  web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());       item = sdList.getItemById(itemID); clientContext.load(web);        clientContext.load(item); clientContext.load(site); clientContext.load(sdList); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded11), Function.createDelegate(this, this.onQueryFailed11));}
function RemoveUnSelectedItemcookie(itemID){ clientContext = SP.ClientContext.get_current();    web =  clientContext.get_web(); site = clientContext.get_site(); sdList =  web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());       item = sdList.getItemById(itemID); clientContext.load(web);        clientContext.load(item); clientContext.load(site); clientContext.load(sdList); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded12), Function.createDelegate(this, this.onQueryFailed12));}
function onQuerySucceeded11(sender, args){ // var webUrl = this.web.get_serverRelativeUrl();//alert(getRootUrl());
var FileLeafRef = "";var FileRef = "";FileLeafRef =this.item.get_item("FileLeafRef");FileRef =this.item.get_item("FileRef");//alert(getRootUrl()+FileRef);createCookie('EmailAttachment',readCookie('EmailAttachment') + '*' + getRootUrl()+FileRef,1) ;//alert("Cookiecreated");var cookietext ="";cookietext =readCookie('EmailAttachment');//alert(cookietext);}


function onQueryFailed11(sender, args){alert('failed. Message:' + args.get_message());}
function onQuerySucceeded12(sender, args){var FileRef = "";FileRef =this.item.get_item("FileRef");
var fileRefArray = readCookie('EmailAttachment').split("*");createCookie('EmailAttachment','null',1) ;
for (var i = 1; i < fileRefArray.length; i++) {                if (fileRefArray[i]!=getRootUrl()+FileRef) { createCookie('EmailAttachment',readCookie('EmailAttachment') + '*' + fileRefArray[i],1) ; }            }
//getOutlook();//eraseCookie(this.sdList.Id+this.item.Id) ;//alert("CookieDeleted");var cookietext ="";cookietext =readCookie('EmailAttachment');//alert(cookietext);}


function onQueryFailed12(sender, args){alert('failed. Message:' + args.get_message());}   function getRootUrl() {    var root;    if (this.site.get_serverRelativeUrl() == "/") {        root = this.site.get_url();    }    else {        var index = this.site.get_url().indexOf(this.site.get_serverRelativeUrl());        root = this.site.get_url().substr(0, index);    }    return root;}function createCookie(name,value,days) {    if (days) {        var date = new Date();        date.setTime(date.getTime()+(days*24*60*60*1000));        var expires = "; expires="+date.toGMTString();    }    else var expires = "";    document.cookie = name+"="+value+expires+"; path=/";}

function readCookie(name) {    var nameEQ = name + "=";    var ca = document.cookie.split(';');    for(var i=0;i < ca.length;i++) {        var c = ca[i];        while (c.charAt(0)==' ') c = c.substring(1,c.length);        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);  
  }    return null;}

function eraseCookie(name) {    createCookie(name,"",-1);}
// Gets all selected itemsfunction GetAllSelectedItems() {    selectedItems = "";//get the cookie URL Path    itemsArray = new Array(selectedItems.length);    for (i = 0; i < selectedItems.length; i++) {        itemsArray[i] = sdList.getItemById(selectedItems[i].id);    }
    for (i = 0; i < selectedItems.length; i++) {        ctx.load(itemsArray[i], "FileRef", "FileLeafRef", "FSObjType");    }    ctx.executeQueryAsync(Function.createDelegate(this, this.succeededSelectedItems), Function.createDelegate(this, this.onQueryFailed));}
function getOutlook() {alert("outlook function");    var outlook;    var otem;    var modalDialog;    try {        modalDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose("Send e-mail", "Please, wait...", 300, 400);        outlook = new ActiveXObject('Outlook.Application');        otem = outlook.CreateItem(0);    var fileRefArray = readCookie('EmailAttachment').split("*");
           for (var i = 1; i < fileRefArray.length; i++) {                otem.Attachments.Add(fileRefArray[i]);            }            fileRefArray = null;            otem.Subject = "Documents from Share Point document library.";                otem.Display();        otem.GetInspector.WindowState = 2;    } catch (err) {        alert("Error: " + err.message + "\n" +        "The following may have cause this error: \n\n" +        "1. The Outlook is not installed on the machine.\n" +        "2. The “Initialize and Script ActiveX controls not marked as safe” option should be selected as “Enable” \n" +            "Open Internet Explorer, go to Tools, Internet Options.\n" +            "Click on the security page and make sure the \"Trusted sites\" zone is selected at the top.\n" +            "Click on the Sites button.\n" +            "Add current site to trusted sites and close the window.\n" +            "Then click on Custom Level at the bottom.\n" +            "In the following window you will see  settings for “Initialize and Script ActiveX controls not marked as safe”,\n" +            "select the option “enable” under the same.\n" + "3. This function was used not inside of share point domain.\n");    } finally {        otem = null;        outlook = null;        if (notification != null) SP.UI.Notify.removeNotification(notification);        SP.UI.ModalDialog.commonModalDialogClose(1, '0');        //SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK); createCookie('EmailAttachment','null',1) ;    }}</script>

Coordinator
Feb 3, 2012 at 2:14 PM

Hi prath_128, I tried to reproduce the behaviour but unfortunatly wasn't successful. I didn't get the code you posted to running. I'll try ones more if I have a bit of time over. Please tell me whether you already solved the problem on your own (cause as well as solution would be interesting for me, too).