Colorize the CRM grid - dynamics-crm

How can I colorize the CRM grid on Dynamics CRM 4?
I would like to automatically display the list of an entity with a back color when loading the view.
My goal is to have different colors depending on the status of the listed entity. For example, I want to have a color for cases that have a date field that is in the past and another color for cases that have this date in the future.

The solution described below is a change not supported by Microsoft (that means, use it at your own risks). Plus, there is no guarantee that it won't be broken when applying CRM rollups.
On the CRM server, modify the C:\Program Files\Microsoft Dynamics CRM\CRMWeb\_static\_grid\grid.htc file:
Add the following code at the end of the initializeData() function:
if (window.location.href.toLowerCase() ==
"http://CrmServerName:5555/OrganizationName/cs/home_cases.aspx") {
// We ensure that we are on the organization we want to colorize and that we
// are on the Cases page
var colorizeColumn = InnerGrid.FindColumnIndex("new_date");
if (colorizeColumn > 0) {
// We ensure that the column we'll use to colorize is present
for (var i = 0; i < InnerGrid.AllRecords.length; i++) {
// For each line
// Build the date value from the displayed date
var new_date_displayed = InnerGrid.AllRecords[i][3].
cells[colorizeColumn].innerText;
var new_date_value = new Date(new_date_displayed.substring(6,10),
new_date_displayed.substring(3,5) - 1,
new_date_displayed.substring(0,2),
new_date_displayed.substring(11,13),
new_date_displayed.substring(14,16), 0, 0);
// Get current date
var current_datetime = new Date();
if (new_date_value <= current_datetime) {
InnerGrid.rows[i].style.backgroundColor="ff0066";
} else {
InnerGrid.rows[i].style.backgroundColor="ff6600";
}
}
}
}
And here's what you get:

Related

Dynamic menu configuration section with conditional inputs on Magento custom module

I've followed this tutorial to create a custom dynamic backend configuration with serialized data, and everything is working as expected. yay
But now I want to take another step and only show some inputs when a specific value is selected in a select box. I know that I can use when doing this with system.xml, but how can I accomplish the same thing via code with dynamics serialized tables?
I ended up doing some kind of Javascript workaround to enable/disable a certain input.
function togleSelect(element)
{
var val = element.value;
var name = element.name;
if (val == 0) // select value to be triggered
{
name = name.substr(0, name.lastIndexOf("[")) + "[name_of_my_input]";
var target = document.getElementsByName(name);
target[0].disabled = false;
}
else
{
name = name.substr(0, name.lastIndexOf("[")) + "[name_of_my_input]";
var target = document.getElementsByName(name);
target[0].disabled = true;
}
}
It's not the best solution but it's working.

Upgrading from 2013 to 2015 version of Kendo - issues with datasource items

Have recently upgraded from a 2013 to 2015 versions of Kendo UI for MVC and am having a bit of an issue with datasource. Can anyone point me at a place in the docs or elsewhere for a few examples of the differences.
Here is one link
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-data
eg: The 2013xxx version way of setting the data
MyDataSource.data(data); //where data was jason array returned from ajax
the 2015 way, at least that works but not sure if right
MyDataSource.data = data;
Also, as for setting values of dataitems, they too seem to have a different approach?
Old way:
var MyDataSource = $('#SalesGrid').data().kendoGrid.dataSource;
var raw = statementBatchDS.data; //raw will be undefined with 2015 version ???
var length = raw.length;
// iterate and reset items
var item, i;
for (i = length - 1; i >= 0; i--) {
item = raw[i];
item.set("SaleAmount", 45.22);
//more code...
}
Now if I change the code to use Data, I get the data items, but then the dataitem set methods fail
Kendo UI Datasource has method data. Its not property so you use it as function. Data method gets or sets the data items of the data source.
var items = [
{ name: "Jane Doe" },
{ name: "John Doe" }
];
var dataSource = new kendo.data.DataSource({});
dataSource.data(items);
var data = dataSource.data();
So, change this line
var raw = statementBatchDS.data;
To this
var raw = statementBatchDS.data();

Calculating age by birthdate field in crm 2013

I need to write a global javascript code that calculates age by birthday field and call the function from a diffrent javascript file to the specific entity.
from some reason i get error message "CalculateAge is undefined" after i loaded my entity javascript file to the form.
This is what i write in the global file:
CalculateAge: function (birthd)
{
if (birthd == null) {
return;}
var today = new Date().getFullYear();
year1 = birthd.getFullYear();
return (today-year1);
}
This is what i write in my entity file that i am loading to the form:
function onLoad() {
var birthDate = Xrm.Page.getAttribute("el_birth_date").getValue();
Xrm.Page.getAttribute("el_age").setValue(CalculateAge(birthDate));
}
I am new in Javascript.. Can ypu please help?
The JavaScript code you are using to calculate the age is not correct, it doesn't consider the month and the day.
A correct version is this one:
function CalculateAge(birthday, ondate) {
// if ondate is not specified consider today's date
if (ondate == null) { ondate = new Date(); }
// if the supplied date is before the birthday returns 0
if (ondate < birthday) { return 0; }
var age = ondate.getFullYear() - birthday.getFullYear();
if (birthday.getMonth() > ondate.getMonth() || (birthday.getMonth() == ondate.getMonth() && birthday.getDate() > ondate.getDate())) { age--; }
return age;
}
and can be used as:
var birthday = Xrm.Page.getAttribute("new_birthday").getValue();
var age = CalculateAge(birthday);
alert(age);
// age on 1st January 2000, JavaScript Date() object contains months starting from 0
var testdate = new Date(2000, 0, 1, 0, 0, 0);
var testage = CalculateAge(birthday,testdate);
alert(testage);
If you get CalculateAge is not defined, probably you didn't include the webresource containing your function inside the form. If you have two JS web resources (one containing the function, the other one containing the onLoad event) both need to be included inside the form.
If you are in a CRM version that has the issue of the asynchronous javascript loading, it's better to include the CalculateAge function in the same file as the onLoad event, but if you prefer keep them separate check this blog post: Asynchronous loading of JavaScript Web Resources after U12/POLARIS
The JavaScript function comes from my blog post: Calculate age in Microsoft Dynamics CRM 2011

Google Maps V3 with MarkerCluster changing the color rules

Using Google Maps V3 with MarkerCluster, you can see three different types of colors when clusertering, based on how many is clustered toghter.
Problem:
I want to change the rule from based on how many, to how serious the case is on that area, its also represented in the custom icons I use. The types im working with is green for a good running product, yellow for a warning and red for a bad product.
I want to be able to see the red color on the cluster icon if there is a bad product in there somewhere, and not at all based on the number..
Im using ASP.NET MVC3 with razor - that maybe could help.
Can this be done guys?
Let's assume:
your cluster image files are in place and have indexes of 1-green; 2-yellow; 3-red;
references to your marker icons (string|Icon|Symbol) are made available as properties of the object, markerIcons
var markerIcons = {
'green': '...',
'yellow': '...',
'red': '...'
};
Then, you can control which cluster icons are displayed with a calculator function as follows :
var myClusterer = new MarkerClusterer(map, {
...,//options
});
mc.setCalculator(function(markers, numStyles) {
var index = 1;//green
loop:
for(var i=0; i<markers.length; i++) {
switch(markers[i].getIcon()) {
case markerIcons.yellow:
index = 2;//yellow
break;
case markerIcons.red:
index = 3;//red
break loop;
break;
}
}
var index = Math.min(index, numStyles);
return {text:markers.length, index:index};
});
you need to change calculator function:
var mc = new MarkerClusterer(map);
mc.setCalculator(
function(markers, numStyles) {
return {text: markers.length, index: 8};
}
);
The function get list of markers and should return a pair : text label and the colour number.

selected Picklist value not saving in dynamic CRM?

I have added javascript for reverse the items in the picklist (rating) to the opportunity entity. It is done. but when I am filling the data and saving it, it is not saving the selected item from the rating picklist to the database. What do I have to do?
var oField = crmForm.all.opportunityratingcode;
var items = oField.options.length;
var arrTexts = new Array(items);
var arrValues = new Array(items);
for(i=0;i<items;i++)
{
arrTexts[i]=oField.Options[i].Text;
arrValues [i]=oField.Options[i].DataValue;
}
for(i=0;i<=items;i++)
{
oField.DeleteOption(i);
}
for(j=items;j>0;j--)
{
var oOption1 =oField.Options;
oOption1.Text=arrTexts[j-1];
oOption1.DataValue= arrValues [j-1];
oField.AddOption(oOption1.Text,oOption1.DataValue);
alert(oOption1.DataValue);
}
Sounds like you need to add a .ForceSubmit in the onSave of the form. This forces CRM to save attribute data changes that you have made with JavaScript.
e.g.
crmForm.all.attribName.ForceSubmit = true;
Check the CRM SDK here: http://technet.microsoft.com/en-us/library/cc189831.aspx

Resources