0

We are creating a custom list. We want a button/link that when clicked, it pulls the title of the specific list item, along with the multiline text, and send it to whoever submitted it. I think this can be done with a workflow but I'm new to this and come up short when googling this. People keep designing workflows for when new list items are created, but I'm needing to copy content of the list item and get it ready for an email. Is this possible?

I can be more specific if necessary.

0
function popup() {
        var ctx = new SP.ClientContext.get_current();
         web = ctx.get_web();
         if (ctx != undefined && ctx != null) {
            var listId = SP.ListOperation.Selection.getSelectedList();
                        var oList = ctx.get_web().get_lists().getByTitle('List name'); // Put your list name here        
            var selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx);
                        var camlquerystr = '';
                      if(selectedItems.length > 0){
                        if(selectedItems.length == 1)
                        {
                            camlquerystr += '<Where><Eq><FieldRef Name=\'ID\'/><Value Type=\'Number\'>' + selectedItems

[0].id + '</Value></Eq></Where>';
                        }
                        else if(selectedItems.length == 2)
                        {
                            camlquerystr += '<Where><Or><Eq><FieldRef Name=\'ID\'/><Value Type=\'Number\'>' + selectedItems

[0].id + '</Value></Eq><Eq><FieldRef Name=\'ID\'/><Value Type=\'Number\'>' + selectedItems[1].id + 

'</Value></Eq></Or></Where>';
                        }
                        else
                        {
                        var i;
                        camlquerystr += '<Where>';
                        for (i = 0; i < selectedItems.length - 1; i++) {
                               camlquerystr += '<Or><Eq><FieldRef Name=\'ID\'/><Value Type=\'Number\'>' + selectedItems

[i].id + '</Value></Eq>';
                        }
                        camlquerystr += '<Eq><FieldRef Name=\'ID\'/><Value Type=\'Number\'>' + selectedItems[i].id + 

'</Value></Eq>';
                        for (i = 0; i < selectedItems.length - 1; i++) {
                               camlquerystr += '</Or>';
                        }
                        camlquerystr += '</Where>';
                        }
                       }
                       else
                       {
                           alert('Please select atleast one item');
                           return false;
                       }
                        var camlQuery = new SP.CamlQuery();
                        camlQuery.set_viewXml('<View><Query>' + camlquerystr + '</Query></View>');
                        this.collListItem = oList.getItems(camlQuery);

                        ctx.load(collListItem, 'Include(Title, Text)'); // include the columns here

                        ctx.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, 

this.failed));
         }



 }

function newCallback(dialogResult, returnValue) { 
       SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK); 
} 

function success() {
    var listItemInfo = "";

    var listItemEnumerator = collListItem.getEnumerator();
        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            var title= oListItem.get_item('Title');

        }


        SP.UI.ModalDialog.showModalDialog({ 
            url: "URL of the X page", 
            title: "Add item", 
            allowMaximize: true, 
            showClose: true, 
            width: 800, 
            height: 600, 
            args:  { 'title': title},
            dialogReturnValueCallback: newCallback 
        });

        }

And in 'X' page you can get the arguments by:

$(document).ready(function(){
args = window.frameElement.dialogArgs;
Newtitle = args['title'];
});

Add a button using the CEWP like <button onclick="popup();">Click here</button>. The above function popup is used to retrieve the information of the selected items from list. You can perform whatever actions needed from this information.

  • I must be doing something wrong. Is there a longer explanation that you know of on adding these to your page and have them display? Appreciate all the help so far :) – mattpe Oct 6 '15 at 15:42
  • Edited my answer – Keerthi Oct 6 '15 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.