Получить все счета для конкретного контакта с помощью инструментария Alexa CRM в Dynamics CRM

Я использую AlexaCRM Toolkit для Dynamics 365 и работаю над сценарием, который приносит мне результаты всех счетов для конкретного контакта, следующий скрипт показывает последние десять счетов, но для разных контактов.

$invoices = $service->retrieveMultipleEntities("invoice", $allPages = false, $pagingCookie = null, $limitCount = 10, $pageNumber = 1, $simpleMode = false);
foreach ($invoices->Entities as $invoice) {

echo 'ID : ' . $invoice->ID . '<br>';
echo 'Name :' . $invoice->name. '<br>';

}

Цель состоит в том, чтобы получить только счета, связанные с конкретным контактом.

1

Решение

Уважаемый @Arun спасибо за взаимодействие, я использовал retrieveMultiple и создаю запрос FetchXML, чтобы получить все относительные счета, это код

$queryXML = "<fetch mapping='logical'>
<entity name='invoice'>
<all-attributes />
<link-entity name='contact' from='contactid' to='customerid'  alias='C'>
<filter type='and'>
<condition attribute='contactid' operator='eq' value='$contact->id' />
</filter>
</link-entity>
</entity>
</fetch>";

$invoices = $service->retrieveMultiple($queryXML, false);
1

Другие решения

Контакт (поиск) — это GUID внешнего ключа в записи объекта Invoice. Без фильтрации значения контакта, которое вы ищете, запрос приведет к 10 случайных счетов сверху.

Попробуйте установить условие WHERE в вашем коде.

Например:
Чтобы отфильтровать контакт по его атрибуту emailaddress1, образец в GitHub выглядеть так:

$contactKey = new \AlexaCRM\CRMToolkit\KeyAttributes();
$contactKey->add( 'emailaddress1', $contactKeyValue );

Еще один пример со ссылкой этот, Вы можете сделать что-то вроде ниже, чтобы отфильтровать конкретный родительский контакт.

/* Check the ID or AlexaCRM\CRMToolkit\KeyAttributes to retrieve the entity values */
if ($IDorKeyAttributes != null) {
/* Set EntityValues if specified Entity ID */
if (is_string($IDorKeyAttributes) && self::isGuid($IDorKeyAttributes)) {
/* Set the ID of Entity record */
$this->setID($IDorKeyAttributes);
/* Get the raw XML data */
$rawSoapResponse = $this->client->retrieveRaw($this, $columnSet);
/* NOTE: ParseRetrieveResponse method of AlexaCRM\CRMToolkit\AlexaSDK_Entity class, not the AlexaCRM\CRMToolkit\AlexaSDK class */
$this->parseRetrieveResponse($this->client, $this->LogicalName, $rawSoapResponse);
} else {
if ($IDorKeyAttributes instanceof KeyAttributes) {
if (version_compare($this->client->organizationVersion, "7.1.0", "<")) {
throw new Exception('Entity ID must be a valid GUID for the organization version lower then 7.1.0');
}
/* Set the keyAttributes array */
$this->keyAttributes = $IDorKeyAttributes;
/* Add the KeyAttribute values to the entity object values */
foreach ($IDorKeyAttributes->getKeys() as $key => $attribute) {
$this->propertyValues[$key] = array("Value" => $attribute, "Changed" => true);
}
/* Get the raw XML data */
try {
$rawSoapResponse = $this->client->retrieveRaw($this, $columnSet);
/* NOTE: ParseRetrieveResponse method of AlexaCRM\CRMToolkit\AlexaSDK_Entity class, not the AlexaCRM\CRMToolkit\AlexaSDK class */
$this->parseExecuteRetrieveResponse($this->client, $this->LogicalName, $rawSoapResponse);
} catch (SoapFault $sf) {
$errorCode = $sf->faultcode;
// undocumented feature
if ($errorCode == '-2147088239') {
$this->exists = false;
}
/* ToDo: Return exception with user-friendly details, maybe KeyAttribute parameters invalid */
}
}
}
}

Примечание: я не php человек, чтобы помочь вам, я сделал некоторые исследования.

0