简体   繁体   中英

MS Dynamics CRM 2011, Get subgrid elements from other form

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);
}

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?

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM