Get days since last modified RRS feed

  • Question

  • What I'm trying to do is get a number for the days since a contact was last modified, which I'll then use elsewhere in our code. I'm new to CRM development, so I'm hoping there's a simple reason why this code is causing the contact record to error out.

    if (context.OutputParameters.Contains("BusinessEntity") && context.MessageName.Equals("Retrieve", StringComparison.InvariantCultureIgnoreCase))
                    Entity contact = context.OutputParameters["BusinessEntity"] as Entity;
                                   if (contact.Attributes.Contains("modifiedon"))
                        DateTime mod = contact.GetAttributeValue<DateTime>("modifiedon");
                        TimeSpan t = DateTime.Today - mod;
                        if (contact.Contains("new_dayssincelastmodified"))
                            contact["new_dayssincelastmodified"] = t.Days;
                            contact.Attributes.Add(new KeyValuePair<string, object>("new_dayssincelastmodified", t.Days));

    Any suggestions, advice, etc. will be greatly appreciated.


    Brent O'Dell

    Wednesday, June 26, 2013 10:41 PM