Skip to content

BULK/Batch Create Records, The quickest way to create multiple new records in Dynamics CRM. #79

Description

@smartinsight-at

What is the best way to approach creating multiple new records in a batch on a a Dynamics CRM. I am successfully creating individual records but this seems a slow process.

I have to create 300,000 records a day in the CRM as a log of all emails sent out by the client. The table has been created and I can do it one record at a time, each post takes about 3-4 seconds. As the time seems to be in the call and response, can I bulk upload e.g 100 records+ at a time and get back an array of Records Id's created in the same way as I get the record Id when I create a single item.

If possible an Example would be appreciated.

Our current method that works for single records is as follows.

    require_once '../vendor/autoload.php';

    $settings = new \AlexaCRM\WebAPI\OData\OnlineSettings();
    $settings->instanceURI = 'https://xxxxxxxxxx.dynamics.com';
    $settings->applicationID = 'xxxxxxx-xxxxxx-xxxx-xxxxx-exxxxxxxxx';
    $settings->applicationSecret = 'Btl8QXXXXXXXXXXXXXXXXXXX';
    $settings->apiVersion = '9.2';

$middleware = new \AlexaCRM\WebAPI\OData\OnlineAuthMiddleware( $settings );
$odataClient = new \AlexaCRM\WebAPI\OData\Client( $settings, $middleware );
$client = new \AlexaCRM\WebAPI\Client( $odataClient );

$record = new \AlexaCRM\Xrm\Entity('xpg_trackedactivity'); // this is to create new existing

$record['xpg_source'] = 930590000;
$record['xpg_description'] = $row['description'];
$record['xpg_campaignname'] = $row['campaignname'];

try {
// run your code here
$externalresult=$client->Create( $record );
$status="Sent";
}
catch (exception $e) {
$status="Error";
//code to handle the exception
echo "error Trapped: ".$e;
}

Many Thanks
Adam Taylor

Activity

  1. georged commented on Jul 4, 2022

    @georged
    Contributor

    Hey Adam,

    Consider batch requests. The toolkit does not have any built-in support for this, you'd have to go down to raw Web API level. You can also spin multiple threads under separate app users (to avoid being throttled) each doing part of the insert.

    Considering that your insert is a simple one, the other options to consider is to try using existing tools like data import or Power Automate.

    HTH
    George

  2. smartinsight-at commented on Jul 4, 2022

    @smartinsight-at
    Author
  3. SpartakusMd commented on Sep 12, 2022

    @SpartakusMd

    Hello, as another recommendation I would suggest to use a cache pool if you don't do it already. We also had slow responses from the CRM as we forgot to plug it. Afterwards, the responses were super fast. The slowest part before was to get the odata and the authentication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions