Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
smartinsight-at opened this issue Jul 1, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@smartinsight-at
Copy link

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

@georged
Copy link
Contributor

georged commented Jul 4, 2022

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

@smartinsight-at
Copy link
Author

smartinsight-at commented Jul 4, 2022 via email

@SpartakusMd
Copy link

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.

@georged georged added the enhancement New feature or request label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants