Get data from selected rows of Sub-Grid

Here is the sample code to get desired data ( sample shows about GUIDS) from selected rows from the editable grid.

function GetSelecctedGuidsFromGrid() {

//Get an array of entity references for all selected rows in the subgrid
    var selectedEntityReferences = [];
    var sGuids = "";
 //get selected rows from grid    
var sRows = Xrm.Page.getControl("booked_asset").getGrid().getSelectedRows();
    
sRows.forEach(function (selectedRow, i) {
        selectedEntityReferences.push(selectedRow.getData().getEntity().getEntityReference());
    });
 //get all required data from each selected row    
for (let i = 0; i < selectedEntityReferences.length; i++) {
        if (sGuids == "") {
            sGuids = (selectedEntityReferences[i].id.toString());        
}
        else {
            sGuids = sGuids + "," + (selectedEntityReferences[i].id.toString());
        }    
}  
//clear field value    
Xrm.Page.getAttribute("soft_selectedassetlist").setValue(""); 
//set attribute value     
Xrm.Page.getAttribute("soft_selectedassetlist").setValue(sGuids);
    Xrm.Page.data.entity.save();
}

Thanks !!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: