php-crm-toolkit
php-crm-toolkit copied to clipboard
CRM 2015 set statuscode and statecode
I get the following error
Property statecode of the new_test entity cannot be set in /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Entity.php on line 271
When I try to update with this:
$test->statecode = 1;
$test->statuscode = 100000000;
I've come across this similar issue https://github.com/AlexaCRM/php-crm-toolkit/issues/24, where the solution was to use SetStateRequest. However, I'm not sure how to implement this solution.
Could you please provide an example?
@Artemy-Matvienko what is your Dynamics 365/CRM version? If it's 2016 or above, setting the attributes should work. statecode 1 is Inactive, are you sure that your custom statuscode is valid for Inactive state?
I don't think we've implemented SetStateRequest
.
Check SoapRequestGenerator and follow the existing methods style to create new request for SetState. Then call it as we do in Client.php, e.g. see delete
method.
If you don't want to write any php, you can try creating custom action in CRM and then call executeAction
.
@georged Are you suggesting that I extend the Client and SoapRequestGenerator classes to accommodate this extra functionality?
I'm assuming the new SoapRequestGenerator function will look something like this:
public static function generateSetStateRequest( Entity $entity ) {
/* Generate the Request message */
$requestDOM = new DOMDocument();
$node = $requestDOM->appendChild( $requestDOM->createElementNS( 'http://schemas.microsoft.com/xrm/2011/Contracts/Services', 'SetState' ) );
$node->appendChild( $requestDOM->createElement( 'entityName', $entity->logicalName ) );
$node->appendChild( $requestDOM->createElement( 'id', $entity->ID ) );
$node->appendChild( $requestDOM->createElement( 'statecode', $entity->statecode ) );
$node->appendChild( $requestDOM->createElement( 'statuscode', $entity->statuscode ) );
/* Return the DOMNode */
return $node;
}
@Artemy-Matvienko yes, you'd need to extend both SoapRequestGenerator and Client. If you fancy the pull request, we can test it and incorporate into the toolkit.
Cheers George