web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    RE: Setting a date using C#, what am I doing wrong?

    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
    RE: Setting a date using C#, what am I doing wrong?

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

  • Hussman Profile Picture
    3,755 on at
    RE: Setting a date using C#, what am I doing wrong?

    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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans