Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Is it safe to bulk update status and state codes by using an SQL query?

Posted on by 285

My company is implementing a record retention policy. I need to update 15,000 records of a custom entity. Specifically, I need to update their statuscode (Not retained), statecode (Inactive), and title (Record deleted as per the company retention policy).

I was thinking of creating a custom PHP script that uses a CRM connection library to do this. I created the script, but the problem is that it takes like 6 hours to update 15,000 records on a dev environment, which seems unreasonably long. This is likely because the update requests are done 1-by-1, so they aren't optimized for efficiency and speed. The php library doesn't seem to have a way to do a more efficient bulk update.

I haven't done much with CRM .NET plugins yet, so I'd rather not get into that for this task, as learning a new pipeline and SDK will bloat the required time to accomplish this task.

Since the CRM is on premise, an obvious solution is to update the SQL database directly through a query. Should be faster since 1 SQL update query would be optimized for bulk updates. However, I've read many times that direct database updates are not supported and can have bad consequences.

I've seen mentions of using a workflow to update the records that match the criteria, but I'm not understanding how it would get triggered. An on-demand workflow would have to be executed manually 30 times since there's the 500 record limit per page in a view.

Do you have any suggestions?

EDIT:

I'm actually thinking of just running my current script overnight. Will give it plenty of time to finish. I only need to do this bulk update once. Afterwards, this same script will run on a schedule at night on a much smaller set of data. Just gotta test the full run on a dev environment first, likely tonight.

*This post is locked for comments

  • Artemy Profile Picture
    Artemy 285 on at
    RE: Is it safe to bulk update status and state codes by using an SQL query?

    XRM Tool Box seems to be the winner for the initial bulk record update. Very simple to set up, and can automatically split the operations in batches of up to 1000! Took around 30 minutes to finish the task on 15,600 records on a low powered dev stack. Expect that time to be cut in half on the more powerful production stack. Definitely a step up from 6 hours!

    The scheduled script will run with php every day on only a few records that would match the retention criteria, so I don't mind it being a bit inefficient or taking up 10 minutes to finish.

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: Is it safe to bulk update status and state codes by using an SQL query?

    Hi Artemy,

    I would update the records using an SSIS Package or a console application. However, the Bulk Workflow Execution Plugin in the XrmToolBox might be the easiest approach for you.

  • Artemy Profile Picture
    Artemy 285 on at
    RE: Is it safe to bulk update status and state codes by using an SQL query?

    I'm concerned that the library and doc you linked are talking about Dynamics 365, but my instance is version 2015. I'm also not sure if that library will work with PHP 5.3. The current PHP library I'm using uses SOAP requests still.

    Do you have much experience with .NET for CRM? Can .NET scripts be run independently on a schedule using Windows task scheduler? I realized that the pipeline won't be too different since I'm not looking to create a plugin, just a script. Are there any links you could point at to get me started?

  • Suggested answer
    Ben Thompson Profile Picture
    Ben Thompson 6,350 on at
    RE: Is it safe to bulk update status and state codes by using an SQL query?

    You could combine 100 of your php calls into a single bulk execute request and run it that way see docs.microsoft.com/.../execute-batch-operations-using-web-api for some guidance and github.com/.../RDynamics seems to be a PHP library that supports batches.

    You really shouldn't be updating the records via SQL. While it may work, it may not and its definitely supported by Microsoft if things went wrong...

    Apart from my first suggestion I really can't give you any better answers.

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