Link to home
Start Free TrialLog in
Avatar of maryigr
maryigr

asked on

CRM 2011 Age

In CRM 2011, I am calcuating Age from a birthday field using java than runs onchange and onload. I would like to be able to run this at night also so that the Age field is updated.
 Is there a way to trigger this via a workflow?  Or is there another option?
This is very frustrating as the person that I work for feels that CRM does these types of things in his words, "out of the box"

{
/* ---------Calculates age --------------- */
if(crmForm.FormType!=1)
{
if(crmForm.all.new_dateofbirth.DataValue!=null)
{
var DOB=crmForm.all.new_dateofbirth.DataValue;
var currDate=new Date();
var age=currDate.getFullYear()-DOB.getFullYear();
age=age-1;
if(currDate.getMonth()>DOB.getMonth())
{
age=age+1;
}
crmForm.all.new_age.DataValue=age;
}
}
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Hi maryigr,

Doing this via workflow will be an expensive operation(in terms of resource consumption and performance) if you have a large volume of records. Also we are talking about a recursive workflow here. So everyday it will spawn n number of instances(n is the number of records against which you are executing this workflow).

You can follow this article and instead of a month you can set 1 day to achieve a recurring workflow. Also read the article carefully to understand performance implications I have just mentioned.

http://crmbusiness.wordpress.com/2011/05/24/crm-2011-how-to-schedule-recurring-workflows-in-crm-2011/

Feel free to ask me if you have any further questions/doubts/concerns.

Regards,
Chinmay.
Avatar of maryigr
maryigr

ASKER

Thanks for your suggestion.  I had actually seen this example of setting up a timer for a recurring workflow and I had already tried it.  I had been searching all over the internet for a solution and had not been able to find one.  For my dateofbirth/age scenario it doesn’t work.  What I did was change the date of birth to one day before and then to one day after and to attempt to trigger the onchange of the javascript.  The javascript failed to trigger which is probably because it is attached to a form and there is no way to reference the form.  As you have pointed out, the performance issues that this workflow would cause CRM would make this not a worthwhile solution anyway.  What I did instead was create a sql query to update the Age field and then create a .bat file to run as a scheduled task.  Do you see a downside to this solution?  Do you think that writing a plugin would be a better solutioin?
ASKER CERTIFIED SOLUTION
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maryigr

ASKER

Thank you very much for your help.
No problem. :)