Php 使用Dynamics CRM中的Alexa CRM toolkit获取特定联系人的所有发票
我正在使用AlexaCRM Toolkit for Dynamics 365,我正在编写脚本,为特定联系人提供所有发票的结果,下面的脚本显示了最后十张发票,但针对不同的联系人Php 使用Dynamics CRM中的Alexa CRM toolkit获取特定联系人的所有发票,php,dynamics-crm,dynamics-365,alexacrm-toolkit,Php,Dynamics Crm,Dynamics 365,Alexacrm Toolkit,我正在使用AlexaCRM Toolkit for Dynamics 365,我正在编写脚本,为特定联系人提供所有发票的结果,下面的脚本显示了最后十张发票,但针对不同的联系人 $invoices = $service->retrieveMultipleEntities("invoice", $allPages = false, $pagingCookie = null, $limitCount = 10, $pageNumber = 1, $simpleMode = false); for
$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>';
}
$invoices=$service->retrievemultiplentities(“发票”、$allPages=false、$pagingCookie=null、$limitCount=10、$pageNumber=1、$simpleMode=false);
foreach($invoices->实体为$invoices){
回显“ID:”.$invoice->ID.“
”;
回显“名称:”。$invoice->Name。“
”;
}
目标是仅获取与特定联系人相关的发票。联系人(查找)是发票实体记录中的外键GUID。如果不过滤您要查找的联系人值,查询将从顶部随机生成10张发票
尝试在代码中设置WHERE条件
例如:
要按其emailaddress1属性筛选联系人,中的示例如下所示:
$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 */
}
}
}
}
/*检查ID或AlexaCRM\CRMToolkit\KeyAttributes以检索实体值*/
if($IDorKeyAttributes!=null){
/*如果指定了实体ID,则设置EntityValue*/
if(is_字符串($IDorKeyAttributes)和&self::isGuid($IDorKeyAttributes)){
/*设置实体记录的ID*/
$this->setID($IDorKeyAttributes);
/*获取原始XML数据*/
$rawSoapResponse=$this->client->retrieveRaw($this,$columnSet);
/*注意:AlexaCRM\CRMToolkit\AlexaSDK\u实体类的ParseRetrieverResponse方法,而不是AlexaCRM\CRMToolkit\AlexaSDK类*/
$this->parseRetrieverResponse($this->client,$this->LogicalName,$rawSoapResponse);
}否则{
if($IDorKeyAttributes instanceof KeyAttributes){
如果(version_compare($this->client->organizationVersion,“7.1.0”,“亲爱的@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);
$queryXML=”
";
$invoices=$service->retrieveMultiple($queryXML,false);