0

I'm currently using JS (items[i].id;) to successfully get the id of selected items in a list view, however, I would like to pull column values from the selected row(s) like "Title" etc. if possible using JS\JQuery. Is there a method for doing this by traversing the DOM instead of using the GetItemById method? Thanks!

Here is the code I'm using...

function WriteSelected() {
    var ctx = SP.ClientContext.get_current();
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var i;

    for (i in items)
        {
            //alert (items[i].id);
        }       
}
  • Please share the code snippet that you are using currently to get the item ID. – Rohit Waghela Apr 19 '17 at 14:14
  • Do you mean you want to use Fields not displayed in the View ?? – Danny '365CSI' Engelman Apr 19 '17 at 14:59
  • No sir. The values I want are already columns in the view. My end goal is to take those values and write them to another list. – Ghoztrider Apr 19 '17 at 15:08
0

I am not sure why you want to use the DOM instead of the ctx object...

[].forEach.call(document.querySelectorAll("tr[class~='s4-itm-selected']")
                ,function(tr){
                               console.log(tr.getAttribute('iid').split(',')[1])
                             }
               );

Gets you the Item ID of all selected TRs

  • Honestly, I don't need the id's of the selected items unless I need to get the value of the columns from the GetItemById method. I just want to get the field values as efficiently as possible and run.. – Ghoztrider Apr 19 '17 at 15:41
  • Then do a .map to get the selected IDs and then a ctx.ListData.Row.filter() ? – Danny '365CSI' Engelman Apr 19 '17 at 15:55
0

There is an object exposed by Sharepoint that you can use which is called WPQ2ListData which contains the current information of the list/grid.

Here's an example snippet to achieve what you need:

var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
items.forEach(function(item){
   console.log('Id selected: ' + item.id);
   var listItem = WPQ2ListData.Row.filter(function(row){
        return row.ID == item.id;
    })[0];
 console.log('List Item:');
 console.log(listItem);
});

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.