Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

unable to update Createdon field??

(0) ShareShare
ReportReport
Posted on by 745


try
{
var fetch = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='100'>
<entity name='kp_opportunityheader'>
<attribute name='kp_opportunityid' />
<attribute name='kp_opportunity' />
<attribute name='createdon' />
<attribute name='kp_opportunityheaderid' />
<order attribute='createdon' descending='false' />
<link-entity name='opportunity' from='opportunityid' to='kp_opportunity' visible='false' link-type='outer' alias='opp'>
<attribute name='createdon' />
</link-entity>
</entity>
</fetch>";


var fetchExpression = new FetchExpression(fetch);
EntityCollection result = _service.RetrieveMultiple(fetchExpression);
System.IO.StreamWriter file = new System.IO.StreamWriter(@"c:\\Data\\OpportunityHeader.txt");
/

if(result.Entities.Count > 0)
{
foreach (var c in result.Entities)
{

string dateTime = ((Microsoft.Xrm.Sdk.AliasedValue)(c.Attributes["opp.createdon"])).Value.ToString();
DateTime date = Convert.ToDateTime(dateTime);
c.Attributes["createdon"] = ((Microsoft.Xrm.Sdk.AliasedValue)(c.Attributes["opp.createdon"])).Value;
//((Microsoft.Xrm.Sdk.AliasedValue)(c.Attributes["opp.createdon"])).Value;
_service.Update(c);

loops = "Updated OpportunityHeader Guid: " + c.Attributes["kpmg_opportunityheaderid"].ToString() + " Opportunity name: " + ((Microsoft.Xrm.Sdk.EntityReference)(c.Attributes["kpmg_opportunity"])).Name;
Console.WriteLine(loops + "\n");

file.WriteLine(loops);


}
}

/* while (multiResponse.EntityCollection.MoreRecords);*/
file.Close();
Console.WriteLine("Finished");
Console.ReadKey();
}

catch (Exception ex)

{
Console.WriteLine("Error while connecting to CRM " + ex.Message);
Console.ReadKey();
}

}

Above is the highlighted line i am using to update created on date . but unable to do the same. No error. successfully executed , but not getting updated.

*This post is locked for comments

  • ScottDurow Profile Picture
    ScottDurow 19 on at
    RE: unable to update Createdon field??

    You can't update the created on - you can only set it using the overriddencreatedon during create of the record.

    Does this answer your question?

  • Pranesh M Juwale Profile Picture
    Pranesh M Juwale 1,196 on at
    RE: unable to update Createdon field??

    May be this link help you out

    www.magnetismsolutions.com/.../how_to_modify_the_created_on_value_of_dynamics_crm_2011_part_1

  • Suggested answer
    RE: unable to update Createdon field??

    To update this field, you might need to update  both fields (createdon and overriddencreatedon).So fetch overriddencreatedon also.

    c["createdon"] = ((DateTime)((AliasedValue)c["opp.createdon"]).Value).Value;

    c["overriddencreatedon"] = ((DateTime)((AliasedValue)c["opp.overriddencreatedon"]).Value).Value;

    try this.

  • Suggested answer
    ScottDurow Profile Picture
    ScottDurow 19 on at
    RE: unable to update Createdon field??

    The createdon field cannot be updated ever and the overridencreatedon can only be used during record creation. Perhaps you could use a quick view form to show the created on of the opportunity?

  • pavana Profile Picture
    pavana 745 on at
    RE: unable to update Createdon field??

    No Not able to update.

  • Suggested answer
    Felippe Profile Picture
    Felippe 796 on at
    RE: unable to update Createdon field??

    You must use "overriddencreatedon" instead.

    The createdOn isn't made to be updated.

    Also see:

    www.magnetismsolutions.com/.../how_to_modify_the_created_on_value_of_dynamics_crm_2011_part_1

    If this solves, please "Like" and "Mark as answer".

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans