Sometimes we get requirement to show colour encoding on sub-grid in CRM 2013 forms. One of the
Queries I received was ways to achieve them. Here is a sample of what I tried on Case sub-grid on
Vanilla CRM Account form:
Here is the script:
I have got of lot of feedback to put more details of where to put scripts and stuff, so here it goes.
Sub-grid name can be found from FORM EDITOR. Refer screen below(Double click the sub-grid will give a property window):
Now the script, Add the below function to form onload
function subGridOnload()
{
var grid = $(‘#accountcasessgrid’); //Replace Grid name here
if (grid == null)
{
// delay one second and try again.
setTimeout(subGridOnload, 1000);
return;
}
if(grid[0] == undefined)
{
// delay one second and try again.
setTimeout(subGridOnload, 1000);
return;
}
if(grid[0].control == undefined)
{
// delay one second and try again.
setTimeout(subGridOnload, 1000);
return;
}
if(grid[0].control == null)
{
// delay one second and try again.
setTimeout(subGridOnload, 1000);
return;
}
if (grid[0].control.get_totalRecordCount() == -1)
{
// delay one second and try again.
setTimeout(subGridOnload, 1000);
return;
}
// logic Replace status names and colours as required
$(‘#accountcasessgrid td’).filter(function() {
return $(this).text() == ‘Resolved’;
}).closest(‘tr’).css(‘background-color’, ‘green’);
$(‘#accountcasessgrid td’).filter(function() {
return $(this).text() == ‘Active’;
}).closest(‘tr’).css(‘background-color’, ‘yellow’);
}
Hope it helps!
Ask your Query : Click here
Note: It is unsupported way and may break in future if Microsoft changes rendering of sub-grids in a future release.
Trying to Learn Dynamics CRM: Download!
Learn Dynamics CRM App on Google Play store
Have you tried this in CRM 2013 SP1 UR1? I never get past “if(grid[0] == undefined)”. grid is defined but never grid[0].
The subgrid on the form is populated though. grid has a context and a selector and the length is zero.
I’m actually trying to replace the old fetchXml code which used SetParameter that doesn’t work now. So, the jquery object gives me another avenue to try to figure it out.
Thanks!
Hi,
I have this code working with online trial.I will try setParameter and let you know.
Regards,
Deepesh
Hi,
Super post…
How can i get this to work when going to the next page in the grid..?
Regards
Lars
Hi Lars,
For that you would need to keep appending the same code attached to grid refresh event. Something like this :
http://www.crmanswers.net/2013/07/bind-function-to-subgrid-refresh.html
Regards,
Deepesh
That i didnt see yet but this is unsupported anyways
You Save My night 😉
Happy to help 🙂
is this work in crm 2015 ?
Hi, this is unsupported script only works on CRM 2013. This is more supported approach: https://dynamicsofdynamicscrm.wordpress.com/2015/05/27/supported-and-upgradeable-approach-to-colour-some-relevant-crm-form-fields-for-dynamics-crm/
Hi Deepesh,
I have to implement the same functionality on CRM 2015 Dashboard. Could yo uhelp please. As far as I understnad you cant add the script directly to dashboard
mathew
Hi Matthew,
This is unsupported script. In dashboard you can develop a html webresource component with dynamic table to do colouring.
Regards,
Deepesh
Hi Deepesh- Does this work in both cloud and on-prem implementations?
This was unsupported customization checked and working in CRM 2013. This will change with each version potentially and will not work in Cloud version as it is CRM 2016.
Has anyone gotten this to work with online CRM 2016? Can’t seem to find any other solutions like this one.
Hi Rodney,
This is unsupported approach and needs to change with each version. A better supported approach is to develop a custom grid.
I will add it in a post soon.
Thanks and Regards,
Deepesh
[…] Adding Row Colours to CRM 2013 Sub-Grids dynamically based on value in cells […]
Has anyone successfully implemented this in Online CRM 2016?
Hi Rodney,
This is unsupported approach and needs to change with each version. A better supported approach is to develop a custom grid.
I will add it in a post soon.
Thanks and Regards,
Deepesh
I did actually, with a little bit of luck, get this to work in 2016 online..
Hi Lars,
Please let me know the snippet so that I will be able to post it later.
Thanks and Regards,
Deepesh
Hi Deepesh,
here’s my snippet.. I have row colours or a picture in my script, dependent on the name of the form. I’m sure it could be more tidy, but i works.!!
And it works with the new rendering engine..
function subGridOnload() {
var grid = Xrm.Page.getControl(‘Potentialer’).getGrid();
if (grid == null) {
setTimeout(function () { subGridOnload(); }, 100);
}
var totalCount = grid.getTotalRecordCount();
if (typeof totalCount == “number” && totalCount == -1) {
setTimeout(subGridOnload, 100, ‘Potentialer’);
return;
} else if (totalCount > 0) {
setTimeout(function() {
var formLabel;
var currForm = Xrm.Page.ui.formSelector.getCurrentItem();
formLabel = currForm.getLabel();
if (formLabel == “Oplysninger FLEET”) {
$(“#Potentialer td”).filter(function() {
return $(this).text() == “rungreen”;
}).html(“”);
$(“#Potentialer td”).filter(function() {
return $(this).text() == “runyellow”;
}).html(“”);
$(“#Potentialer td”).filter(function() {
return $(this).text() == “runred”;
}).html(“”);
} else {
$(“#Potentialer td”).filter(function() {
return $(this).text() == “rungreen”;
}).closest(“tr”).css(“background-color”, “rgb(196, 215, 155)”);
$(“#Potentialer td”).filter(function() {
return $(this).text() == “runyellow”;
}).closest(“tr”).css(“background-color”, “#FAF5B6”);
$(“#Potentialer td”).filter(function() {
return $(this).text() == “runred”;
}).closest(“tr”).css({“color”: “#B80000”, “font-weight”: “120”});
};
var filteredRecordCount = Xrm.Page.getControl(‘Potentialer’).getGrid().getTotalRecordCount();
Xrm.Page.data.entity.attributes.get(“new_antal”).setValue(filteredRecordCount);
}, 50);
}
}