Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

DateTime value is null, but I'm not updating a DateTime field.

Posted on by 10

I'm attempting to update a Boolean field through a Dataverse Plugin. I'm currently getting an error.

Error Message:  Exception Message: Date is less than the minumum value supported by CrmDateTime. Actual value: 01/01/0001 00:00:00, Minimum value supported: 01/01/1753 00:00:00

I know what you're thinking...  Your datetime field is null, you need to check for null first and not use it if it's null..  Yep, that's what all the forums say as well as all of the help info I can find. The problem is that I'm not updating a DateTime field. I'm pulling an Entity with a custom ColumnSet of a single field, which is a Boolean. I'm updating the Boolean then updating the Entity.  No dates involved. Maybe 1 out of every 5 runs of the code below results in this error.  I did check to see if there are any required fields in the table that are DateTime fields. There are two, and they're always filled in.  Anyone have an idea as to what is going on here?

if (FoundStudent && !Rejected)
                {
                    EntityCollection EnrollAYList = service.RetrieveMultiple(new FetchExpression(string.Format(fetchEnrollAY, Student.Id, AwardYear.Id, AwardYear.Id)));

                    if (EnrollAYList.Entities.Count > 0)
                    {
                        foreach (var AY in EnrollAYList.Entities)
                        {

                            Guid AY_ID = ((Guid)AY.GetAttributeValue("pt_enrollmentacademicyear1.pt_enrollmentacademicyearid").Value);
                            Entity EnrollAY = service.Retrieve("pt_enrollmentacademicyear", AY_ID, new ColumnSet("pt_autocreateawards"));

                            if (EnrollAY.Contains("pt_autocreateawards"))
                            {
                                EnrollAY["pt_autocreateawards"] = true;
                            }
                            else
                            {
                                EnrollAY.Attributes.Add("pt_autocreateawards", true);
                            }
                            service.Update(EnrollAY);
                        }
                    }
                }

pastedimage1681409604396v1.png

pastedimage1681409996785v2.png

pastedimage1681410056615v3.png

pastedimage1681410233225v5.png

pastedimage1681410172487v4.png

  • Gene_B Profile Picture
    Gene_B 10 on at
    RE: DateTime value is null, but I'm not updating a DateTime field.

    @Andrew, thanks for the suggestion. I looked around and found a plugin written by an ex-employee that was causing the issue. Removed the plugin (wasn't needed any longer) and it seems to have resolved the issue.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: DateTime value is null, but I'm not updating a DateTime field.

    Hello,

    You're a little over-engineering. There is no need to retrieve the record to update it. Also, there is no need to check if the value exists in the field. You can use the code similar to the following:

    if (FoundStudent && !Rejected) {
      EntityCollection EnrollAYList = service.RetrieveMultiple(new FetchExpression(string.Format(fetchEnrollAY, Student.Id, AwardYear.Id, AwardYear.Id)));
    
      foreach(var AY in EnrollAYList.Entities) {
    
        Guid AY_ID = ((Guid) AY.GetAttributeValue < AliasedValue > ("pt_enrollmentacademicyear1.pt_enrollmentacademicyearid").Value);
    
        Entity EnrollAY = new Entity("pt_enrollmentacademicyear", AY_ID) {
          ["pt_autocreateawards"] = true
        };
        service.Update(EnrollAY);
      }
    }

    Your code doesn't look like it causes the issue. It seems that your code triggers some other plugin/real-time workflow/business-rule that causes the issue you describe. I would recommend checking it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans