Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Want to update/insert "created by" and "modified by" date in incident entity using organization.svc

Posted on by Microsoft Employee

I am migrating my old database tables to new using migration utility, where

I want to update created by, modified by column in incident entity, CRM 2016.

But it is taking my default service account user into these column.

I have used Organization.svc service to Create request.

AttributeCollection attCollection = new AttributeCollection();

attCollection.Add(new KeyValuePair<string, object>(CaseColumn.OverriddenCreatedOn, Row.CreatedOn));


if (!Row.CreatedBy_IsNull)
{
EntityReference CreatedByReference = new EntityReference();
CreatedByReference.LogicalName = "systemuser";
CreatedByReference.Id = new Guid("2D96B2C4-DAC5-E611-8114-005056BB7CAE");
attCollection.Add(new KeyValuePair<string, object>(CaseColumn.createdby, CreatedByReference));
}

entityCaseIncident.Attributes = attCollection;

OrganizationRequest request = new OrganizationRequest();
request.RequestName = "Create";
request.Parameters = new ParameterCollection();

request.Parameters.Add(new KeyValuePair<string, object>("Target", entity));

OrganizationResponse response = CommonFunctions.serviceProxy.Execute(request);

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Want to update/insert "created by" and "modified by" date in incident entity using organization.svc

    string ns = "schemas.microsoft.com/.../Contracts&quot;;

     OrganizationResponse orgResponse;

                   using (var scope = new OperationContextScope(CommonFunctions.serviceProxy.InnerChannel))

                   {

                       var userHeader = MessageHeader.CreateHeader("CallerId", ns, createdByUserId);

                       OperationContext.Current.OutgoingMessageHeaders.Add(userHeader);

                       orgResponse = CommonFunctions.serviceProxy.Execute(Requests);

                   }

    I have used this code and worked for me, I am using CallerId concept, so I have updated caller with created by user.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Want to update/insert "created by" and "modified by" date in incident entity using organization.svc

    It seems it worked here:

    www.inogic.com/.../change-createdbymodifiedby-field-at-runtime-in-dynamics-crm-plugin

    But I'm really not sure what's happening in your code.. You are assigning attCOllection to the attributes of the entytCaseIncident, but, then you are using entity as a target. Are you sure you are using those variables in the right places?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Want to update/insert "created by" and "modified by" date in incident entity using organization.svc

    Thanks for reply, but is there any chance or trick that I can do this?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Want to update/insert "created by" and "modified by" date in incident entity using organization.svc

    In my business scenario, I am migrating my 2013 project cases to new system using ETL job, where I don't want to change created by user and modified by user names. I am using service organization service, I don't want to change this using SQL database.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Want to update/insert "created by" and "modified by" date in incident entity using organization.svc

    Hello,

    If I'm not wrong this is usual behavior how it works. The only system field you can set during creation is CreatedOn. To populate it with data pass original createdon to overriddencreatedon. You will not be able to set createdby/modifiedby those fields are populated by system.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans