1
votes

I am new to jscript and have problems to get all elements in a subgrid. I tried the code from this sites,

Retrieve rows in crm2011 subgrid with JScript

https://lakshmanindian.wordpress.com/2012/05/25/retrieve-subgrid-rows-in-crm-2011-using-jscript/

but get every time the error message:

(Translated)


Error in the user defined event of the field

Field:window

Event: onload

Error: The preference "control" of a undefined or null reference can not be called.


The last code I tried:

var grid = document.getElementById("accountContactsGrid").control;
for (var rowNo = 0; rowNo<grid.getRecordsFromInnerGrid().length; rowNo++)
  for (var cellNo = 0; cellNo<grid.getRecordsFromInnerGrid()[rowNo][3].cells.length; cellNo++)
     alert(grid.getRecordsFromInnerGrid()[rowNo][3].cells[cellNo].outerText);

I tried it in the entity Account(Company) with the subgrid "accountContactsGrid".

My main goal would be to catch all the assigned elements in the account form and list it under the contacts form. But only if the checkbox "Eko" is activated.

This is my working code so far:

var chkEko = Xrm.Page.getAttribute("testcrm_ekonomi").getValue();
if (chkEko === true)
{
    alert("Eko active: " + chkEko);
}
else
{
    alert("Eko not active: " + chkEko);
}
2
Are you looking for something as below? [How to write this in jQuery “window.parent.document.getElementById('parentPrice').innerHTML”?][1] [Targetting parent window using jQuery][2] [1]: stackoverflow.com/questions/726816/… [2]: stackoverflow.com/questions/18372746/…Renjith
No sorry i am searching for the Xrm (CRM) code to catch the elements in the grid. I have to use this because, I need to get data from an other form. As I understand so far the only way to get elements from other forms are only the Xrm.. way.user3772108
How about you retrieve this records, you make a call with oData or Fetch, and retrieve all the related entities asociates with your parent entitty?Sxntk
But this looks like a workaround and not like the build in CRM solution. It must be possible with a CRM code. I mean is this the first time someone wants to do such things?user3772108

2 Answers

0
votes

After a time and the help of some threads I was able to get information of this grid. But now I have the problem to catch the elements. I looked up the variable "grid" and found out that variable is an Object. Since I don't really know the properties of the objects I tried to get it all. But it seems, that my code doesn't work and I can not understand why. Here is the code so far:

function subgridItemCount() {

// Get the Subgrid Control
var grid = Xrm.Page.ui.controls.get('accountContactsGrid')._control;

var keys = Object.keys(grid);

var getKeys = function(obj){
    var keys = [];
    for(var key in obj){
        keys.push(key);
    }
    return keys;
}
    for(var i = 0; i<keys.length; i++) {
    document.write(keys[i]);    
    }
}

First I wanted to get the property of the object and then the propertyValue. Or is there an other way to get all values of an object?

0
votes

It seems like I am on the wrong way. This is what I try to do:

In the account/company form is an existing grid which is called Contacts. In this field are some Contacts assigned (with the button "add existing contact").

Now when I open some Contact there should be a box/grid/iframe with a list of all companies this contact is assigned too.

This list should be linked to the Companies (When i click on them CRM should open the form).

Maybe someone can give me a tip? My plan was first to look for all companies and then to compare the assigned contacts to the opened one with some Jscript. Then the script should list all matching contacts in the contact form.

This way is not really performant since the script needs to read all companies first. But I don't know an other way...