Search code examples
linqdynamics-crmdynamics-crm-online

Dynamics CRM Linq validation


I'm trying to update some records in CRM online. When the record is saved, there is some other existing data in the case record that doesn't validate. Can I somehow override validation and just do the update for the single field I"m updating? this is the code:

var closedCases = (from o in xrm.IncidentSet
                where o.StateCode == 1
                               select o).Take(5).ToList();
            foreach (var c in closedCases)
            {
                var numDays = ((TimeSpan)(c.new_ClosedDate - c.CreatedOn)).Days;
                Console.WriteLine("case age: {0}, closed case:{1}", numDays, c.Description);
                c.new_caseage = numDays;
                xrm.UpdateObject(c);
                xrm.SaveChanges();
            }
            Console.WriteLine("changes saved");

Solution

  • first you need to use also UpdateObject if you want to save your changes:

    c.new_caseage = numDays;
    xrm.UpdateObject(c);
    xrm.SaveChanges();
    

    second you can't update closed cases, you need to reopen the records first in order to update.