1. CreatedOn
2. CreatedBy,
3. ModifiedOn,
4. ModifiedBy
And we often think to update the database directly, yes, it is actually possible.
But, beside it is unsupported way, it is only applicable for those who implement CRM OnPremise, but in fact, we also have another CRM Online.
So, to update those fields using SDK, you can use these code lines:
TargetEntity["createdon"] = new DateTime(2011, 8, 8); TargetEntity["overriddencreatedon"] = new DateTime(2011, 8, 8); TargetEntity["createdby"] = new EntityReference("systemuser", new Guid("DDF26A49-4CBA-E311-9400-001CC4EECDD6")); TargetEntity["modifiedby"] = new EntityReference("systemuser", new Guid("F1F26A49-4CBA-E311-9400-001CC4EECDD6")); TargetEntity["modifiedon"] = new DateTime(2012, 8, 8);Do not forget to change to your dynamic values for those assigned field values.
*You should use Late Bound since you cannot use Early Bound:
It will give error says “it is read only”;
And here is the result:
Hope it helps!
Hi
ReplyDeleteDo you have a sample project for this code, I have been trying to do this with Dynamics CRM Online and I am having no success. I have tried a console app, a custom workflow (no success) and a plugin (seems to work for a single record, but isn't working for a bulk import).
If you have any guidance I would be really grateful.
Hi Jonathan,
ReplyDeleteI've tried using the plugin and console apps.
You are trying to create custom import?
Could you please supply more sample code, I do not fully understand how to do this from reading this blog post. I've tried to update "modified on" field by doing the entity.attributes["modifiedon"] = __ method, but this does not work. And looking around online, this is about the only place on the entire world wide web that says this is not impossible to do via API , therefore I feel you should supply some more information when you say this can be done.
ReplyDeleteHI Simon,
DeleteYes, basically many websites said it is not possible, and if I use Early Bound it is also not possible.
I used the code inside a plugin and it worked after I tried the impossible.
Thx.
I'v tried to do this in a console app.
ReplyDelete"createdon" is overridden by the current datetime. The "overriddencreatedon" stores the date in the "createdon". That's what I want.
But... "createdby" and/or "createdonbehalfby" cannot be set. The values are overridden by the logged in user.
I guess you need a plugin to override it back again, like what I did.
Deletecreatedonbehalfby I haven't tried.
Thanks.
Hi Aileen... I can't update createdby field with you istructions! :-(
ReplyDeleteMarco,
ReplyDeleteI tried using plugin and it worked, captured in the picture..
Now for other apps, to be honest I am becoming unsure, need to try again, thanks Marco for the comment.:)
Aileen Nice Blog!! Same thing I'm doing in CRM2015 online version by C# but it's only updating Created on Field but Created by and Modify by is not updating.
ReplyDeleteCan you tell me in CRM2015 it will work???
I have just tested it against CRM 2015 On-line spring release and it worked fine. The trick here is that you MUST register the plug-in step on Pre-Operation execution and just update the incoming target entity in the plug-in context. You don't need to use service.update as well as it is in Pre-Operation it will be updated at the end of the execution pipeline. The code is as below:
ReplyDeleteHope that help.
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = factory.CreateOrganizationService(context.UserId);
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
entity["modifiedon"] = new DateTime(2013, 8, 8);
}
}
I too can confirm this solution does work if you want the status to remain a default status for the activity. However if you attempt to set the status during data migration it 1) Creates the record 2) Updates the status of the record. Unfortunately, during this second stage, it updates the Modified On and Modified By to be the time of the import and which ever user you chose to import the data as. To get around this you need to first create a flag in your CRM entity and each import record (default to false). Then cut an additional plugin message step for the Update:
ReplyDeleteif (preImageEntity.Contains("csp_ismigrationcomplete") && (bool)preImageEntity["csp_ismigrationcomplete"] == false && preImageEntity.Contains("csp_sugarmodifiedon"))
{
localContext.TracingService.Trace("PrePhonecallUpdate: Setting the Modified On Date equal to the Sugar Modified On Date.");
targetEntity["modifiedon"] = (DateTime)preImageEntity["csp_sugarmodifiedon"];
targetEntity["csp_ismigrationcomplete"] = false; //ensure we set it only once
}
I am not sure if you need both Create and Update but possibly records with efult status may not fire the update. You'd certainly need it for any records that didn't have a status set during import.
All a bit clunky but does the job.
I know this is a very old post, but it's one of the only ones that comes up when searching for this topic.
DeleteI just tried this recently in Dynamics 365 when importing Activities and had the following results:
Using the "Pre-Operation-Create" plugin to set the modifiedon date worked fine as long as the Activity is Open
If the Activity is closed, the migration (performed in SSIS with Kingswaysoft) appears to do the insert as two steps:
1. Create the Activity
2. Update the Activity with the "close" state
The second operation (the update) of course then overrides the modifiedon date again.
I saw the post by Ashley Childs where they then write a second plugin for the "Pre-Operation-Update" however when I tried this it didn't work for me
As I could not get the update working I had to revert all my changes because the mixed results (correct date for open records, wrong date for closed records) was a more confusing result for my client
Thanks Aileen, helped me today for CRM 2015 migration.
ReplyDeleteThanks! Above code works for CRM 2016 online.
ReplyDeleteCould you explain how you did it please?
DeleteThanks Aileen!! Above code works for Dynamics 365 online.
ReplyDeleteCould you explain how you did it please?
DeleteHi there,
ReplyDeleteI have inserted several notes but their createdon date are the date i ran the program.
I know i could borrow overridencreatedon to keep historical date.
Does overridencreatedon could only be updated on record create?
Thanks
Randy
Just wanted to say I love to go through your blog and look forward to all your posts!
ReplyDeleteKeep up the superb work!
Customized CRM Solutions
Customer Relationship Management Solutions in Bangalore
Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.
ReplyDeleterpa training in bangalore
rpa training in chennai
rpa training in pune
best rpa training in bangalore
It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
ReplyDeletepython training in chennai
python course in chennai
python training in bangalore
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeleteAWS Training in Bangalore
AWS training in sholinganallur
AWS training in Tambaram
AWS training in Velachery
Visit for AWS training in Bangalore:- AWS training in Bangalore
ReplyDeleteThanks for sharing the information...
ReplyDeleteAWS Training in Bangalore | AWS Cours | AWS Training Institutes - RIA Institute of Technology
- Best AWS Training in Bangalore, Learn from best AWS Training Institutes in Bangalore with certified experts & get 100% assistance.
Really nice post. Thank you for sharing amazing information...
ReplyDeleteAWS Training in Bangalore
Really Great Post & Thanks for sharing.
ReplyDeleteOflox Is The Best Airtel Fancy Numbers & Airtel VIP Number Seller.
ReplyDeleteI am very happy when read this blog post because blog post written in good manner and write on good topic. Thanks for sharing valuable information about AWS Course.
Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
Top Digital Marketing training in India with Customized Digital Marketing course for All. Classroom, Online and Bootcamp classes by Experienced Trainers. To know more please visit our website.
ReplyDeletehttps://onlineidealab.com/digital-marketing-courses/
The article was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents.
ReplyDeleteby Cognex offers AWS Training in Chennai, Microsoft azure, prince2 foundation courses are also available in cognex.
Best IT Training in Chennai
ReplyDeletevirtual learning platforms
ReplyDeleteschool management app
school management software
school erp software
classroom management software
Simply wish to say your article is as astonishing. The clarity in your post is simply great, and I could assume you are an expert on this subject. Same as your blog i found another one Oracle Project Portfolio Management Cloud Software .Actually I was looking for the same information on internet for Oracle PPM and came across your blog. I am impressed by the information that you have on this blog. Thanks a million and please keep up the gratifying work.
ReplyDeletenice article
ReplyDeletekeep sharing this
full stack developer course
full stack developer course in Bangalore
I would like to take this opportunity to thank the author for his incredible work. I believe Customer relationship management is essential for every business to create a loyal customer base. keep doing it. all the best
ReplyDeletetop accounting software
Thanks for providing this information it was rally helpful for . I got to know that these are the points which we should kep in mind while purchasing a marketing tool. Want to read more then please check out the best 10 CRM software in 2022.
ReplyDeleteWe SVJ Technocoat are the leading Service Provider and Exporter of an extensive array of PVD Coating Service and Vapor Deposition Coating Service etc. We are a well known firm for providing excellent quality coating services across the nation and in a timely manner. Owing to our improvised business models, our professionals are offering integrated solutions for our clients.
ReplyDelete