AlexaCRM / dynamics-webapi-toolkit

Dynamics 365 Web API Toolkit for PHP
MIT License
75 stars 58 forks source link

When updating a record using an id that does not exist, it creates an unwanted blank record #94

Open smartinsight-at opened 12 months ago

smartinsight-at commented 12 months ago

When I update specific fields for a record in Dynamics, if the record has since been removed (Deleted) from Dynamics, it creates blank record in its place rather than just failing as the id was not found.

What I want is a safe method of updating that will not create lots of new records when the client removes them from the CRM.

I am sure I am doing something wrong in my code, but I do not know what.

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

      $recordeng  = new \AlexaCRM\Xrm\Entity( 'contact', $row['externalid'] );
      $recordeng['engagementscore']  = $row['score'];

        try {
            // run your code here
            $externalresulteng=$client->update( $recordeng );

        }
        catch (exception $e) {
       echo "<br>error Trapped: ".$e."<br>";    
       }

This seems to relate to me pushing the id for a record that has now been removed, hence it creates the record.

georged commented 11 months ago

@smartinsight-at we need to implement Limit upsert operations. I'm thinking of this (preudo) syntax:

$client->update( $recordeng, LimitUpsert: NONE (default) | LimitUpsert: NOCREATE | LimitUpsert: NOUPDATE );

smartinsight-at commented 11 months ago

Hello George, I hope you are well, it has been a while since we have spoken. Thank you for your reply. That seems to make sense. I will try to work out how to add that to my request.RegardsAdamSent from my iPhoneOn 3 Oct 2023, at 8:01 am, George Doubinski @.***> wrote: @smartinsight-at we need to implement Limit upsert operations

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

georged commented 11 months ago

If you get it done in a generic fashion, please submit a PR 😊