web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Setting a date using C#, what am I doing wrong?

(0) ShareShare
ReportReport
Posted on by 3,755

I have the code below that is giving me an error:

#region
if (entity.Contains("account") && entity["account"] != null)
{
EntityReference a = (EntityReference)entity.Attributes["account"];

//DateTime today = DateTime.Today;

Entity notes = new Entity("account");
notes.Id = a.Id;
notes.Attributes.Add("new_callstoday", new DateTime(today));
service.Update(notes);
}
#endregion

 

I am trying to add todays date to a field.

Can anyone help?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Hi Hussman,

    Change to this:

    if (entity.Contains("account") && entity["account"] != null)

    {

    EntityReference a = (EntityReference)entity.Attributes["account"];

    DateTime today = DateTime.Today;

    Entity notes = new Entity("account");

    notes.Id = a.Id;

    //notes.Attributes.Add("new_callstoday", new DateTime(today));//

    notes.Attributes.Add("new_callstoday", DateTime.UtcNow);

    service.Update(notes);

    }

  • Hussman Profile Picture
    3,755 on at

    Hi thank you for the amendment, but it did not work. I got a plugin error.

  • Hussman Profile Picture
    3,755 on at

    Sorry, yes it did work. Thank you Aileen.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans