<attribute name="accountid" />
      <attribute name="name" />
    </link-entity>
  </entity>
</fetch>
END;
    echo date('Y-m-d H:i:s') . "\tFetching Contact & Account ID for Contact {$demoContactEmail}... ";
    $contactIdData = $crmConnector->retrieveMultiple($contactQueryXML);
    echo 'Done' . PHP_EOL;
    $contactId = $contactIdData->Entities[0]->contactid;
    $accountId = $contactIdData->Entities[0]->parentcustomer->accountid;
    /* Create a template Account, using this ID */
    $account = new DynamicsCRM2011_Account($crmConnector);
    $account->ID = $accountId;
    /* Create a template Contact, using the Contact ID */
    $contact = DynamicsCRM2011_Entity::fromLogicalName($crmConnector, 'contact');
    $contact->ID = $contactId;
    /* Create a new Case, linked to this Account */
    $case = new DynamicsCRM2011_Incident($crmConnector);
    $case->Title = 'Test Case - Using DynamicsCRM2011 from PHP';
    $case->CustomerID = $account;
    $case->ResponsibleContactId = $contact;
    $case->Description = 'This is the case Description, it\'s supposedly a "Memo" field, but actually just treated as a string!';
    /* Before Creating the Case, check if any Mandatory fields are missing */
    $missingFields = array();
    if (!$case->checkMandatories($missingFields)) {
        echo 'Missing Mandatory Fields: ' . PHP_EOL;
        print_r($missingFields);
        echo PHP_EOL . PHP_EOL;
    }
    /* Note that Dynamics CRM 2011 often recovers from missing Mandatory fields, so
 /**
  * Generate an Update Request
  * @ignore
  */
 protected static function generateUpdateRequest(DynamicsCRM2011_Entity $entity)
 {
     /* Generate the UpdateRequest message */
     $updateRequestDOM = new DOMDocument();
     $updateNode = $updateRequestDOM->appendChild($updateRequestDOM->createElementNS('http://schemas.microsoft.com/xrm/2011/Contracts/Services', 'Update'));
     $updateNode->appendChild($updateRequestDOM->importNode($entity->getEntityDOM(), true));
     /* Return the DOMNode */
     return $updateNode;
 }