saintsystems / dynamics-sdk-php

Microsoft Dynamics 365 SDK for PHP
MIT License
37 stars 27 forks source link

how can I update/ create/ delete #8

Closed ebrahimradi closed 1 year ago

ebrahimradi commented 1 year ago

info: $oClient = ODataClient();

and

use SaintSystems\OData\Entity;

class Vendor extends Entity

then $oClient->setEntityReturnType(Vendor::class); $dataArray = $oClient->from("data/VendorsV3") ->where('OrganizationNumber', $organizationNumber) ->get();

`        /** @var Vendor $vendor */
    $vendor = $dataArray->first();

    $vendor->CompanyChainName = "test";
    $this->IODataClient
        ->from("data/VendorsV3")
        ->patch($vendor);`

it cause error: method_exists(): Argument #1 ($object_or_class) must be of type object|string, int given

so i fixed it by editing vendor/saintsystems/odata-client/src/ODataRequest.php:378 to if ((is_object($arrayValue) || is_string($arrayValue)) && method_exists($arrayValue, 'getProperties')) {

and then after call i got this error: Client error:PATCH https://XXX.dynamics.com/data/VendorsV3resulted in a400 Bad Requestresponse: { "error":{ "code":"","message":"An error has occurred.","innererror":{ "message":"More than one resource (truncated...)

  Generally speaking, do you have some examples how can I do update/create/delete ?
ebrahimradi commented 1 year ago

till now, I find out that I cannot use like this. we have to use it like:

$oClient ->patch( 'data/VendorsV3' . '(' . implode(',', [ "VendorAccountNumber='" . $vendor->VendorAccountNumber . "'", "dataAreaId='" . $vendor->dataAreaId . "'" ]) . ')' , ['VendorOrganizationName' => 'test'] );