Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Anytime a vendor writes a four part blog series on how to do something as simple as finding a birthday (as Microsoft did in 2007), you have to know this won't be simple. So far as I can tell, this hasn't updated since then.</p> <ul> <li><a href="http://blogs.msdn.com/b/crm/archive/2007/05/17/find-contacts-with-upcoming-birthdays.aspx" rel="nofollow noreferrer">Find contacts with upcoming birthdays</a></li> <li><a href="http://blogs.msdn.com/b/crm/archive/2007/05/17/find-contacts-with-upcoming-birthdays-ii.aspx" rel="nofollow noreferrer">Find contacts with upcoming birthdays - Part 2</a></li> <li><a href="http://blogs.msdn.com/b/crm/archive/2007/05/17/find-contacts-with-upcoming-birthdays-iii.aspx" rel="nofollow noreferrer">Find contacts with upcoming birthdays - Parts 3 and 4</a></li> </ul> <p>So you have limited options:</p> <ol> <li>Make new fields called something like <code>new_birthmonth</code> and <code>new_birthday</code> that's updated every time a contact is created or updated via a plugin, and then query on those <code>int</code> fields.</li> <li>Using <a href="https://stackoverflow.com/questions/848415/linq-dynamic-where-clause" title="LINQ - dynamic WHERE clause?">Dynamic Linq</a>, construct an <code>OR</code> clause in your <code>WHERE</code> clause that checks to see if the birthday falls in a reasonable range of years (say, 140 for the long-livers) (code below).</li> </ol> <pre class="lang-cs prettyprint-override"><code>List&lt;string&gt; birthdays = new List&lt;string&gt;(); //will contain list of OR clauses //makes sure no CRM unsupported dates are passed (less than 1/1/1900) for (int i = Math.Min(140, DateTime.Today.Year - 1900); i &gt; -1; i--) { //adds a different date per year birthdays.Add ( string.Format ( //DateTimes are stored in UTC "BirthDate = DateTime.Parse(\"{0}\")", DateTime.Today.ToUniversalTime().AddYears(-i) ) ); } //completes the correct dynamic linq OR clause string birthdayList = string.Join(" OR ", birthdays); var getBirthdays = orgContext.CreateQuery&lt;Xrm.Contact&gt;() .Where(c =&gt; c.BirthDate != null) .Where(birthdayList) .ToList(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload