Exemplo n.º 1
0
 /**
  * Send a Retrieve request to the Dynamics CRM 2011 server and return the results as raw XML
  * This function is typically used just after creating something (where you get the ID back
  * as the return value), as it is more efficient to use RetrieveMultiple to search directly if
  * you don't already have the ID.
  * This is particularly useful when debugging the responses from the server
  *
  * @param Entity $entity the Entity to retrieve - must have an ID specified
  * @param array $columnSet array listing all fields to be fetched, or null to get all fields
  *
  * @return string the raw XML returned by the server, including all SOAP Envelope, Header and Body data.
  * @throws Exception
  */
 public function retrieveRaw(Entity $entity, $columnSet = null)
 {
     /* Determine the Type & ID of the Entity */
     $entityType = $entity->LogicalName;
     /* Send the security request and get a security token */
     $securityToken = $this->authentication->getOrganizationSecurityToken();
     /* Check if entity have and ID */
     if ($entity->ID != self::EmptyGUID) {
         $entityId = $entity->ID;
         $executeNode = SoapRequestsGenerator::generateRetrieveRequest($entityType, $entityId, $columnSet);
         $action = "Retrieve";
     } else {
         if ($entity->keyAttributes) {
             $executeNode = SoapRequestsGenerator::generateExecuteRetrieveRequest($entityType, $entity->keyAttributes, $columnSet);
             $action = "Execute";
         } else {
             /* Only allow "Retrieve" for an Entity with an ID */
             throw new Exception('Cannot Retrieve an Entity without an ID or KeyAttributes.');
         }
     }
     /* Turn this into a SOAP request, and send it */
     $retrieveRequest = $this->generateSoapRequest($this->settings->organizationUrl, $this->soapActions->getSoapAction('organization', $action), $securityToken, $executeNode);
     $soapResponse = self::getSoapResponse($this->settings->organizationUrl, $retrieveRequest);
     return $soapResponse;
 }