Dynamics CRM 2016: Do not retrieving account id us

2019-09-15 18:55发布

问题:

In following code snippet I am trying to get child accounts if parent account id matched. It is populating the account name as expected such as ABC Title Company or Test Tile Co. but it populates account id as undefined.

I XRM Service Toolkit for retrieving the details of child account at CRM 2016. I don't know what went wrong in case of account id I double checked the spellings of the attribute but nothing get in favor.

functiongetChildAccounts(pAccountId)
{
var query =
            "<a:ColumnSet>" +
            "<a:AllColumns>false</a:AllColumns>" +
            "<a:Columns xmlns:b='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>" +
            "<b:string>name</b:string>" +
            "<b:string>accountid</b:string>" +
          "</a:Columns>" +
        "</a:ColumnSet>" +
        "<a:Criteria>" +
          "<a:Conditions />" +
          "<a:FilterOperator>And</a:FilterOperator>" +
          "<a:Filters>" +
"<a:FilterExpression>" +
  "<a:Conditions>" +
    "<a:ConditionExpression>" +
      "<a:AttributeName>parentaccountid</a:AttributeName>" +
      "<a:Operator>Equal</a:Operator>" +
      "<a:Values xmlns:b='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>" +
        "<b:anyType i:type='c:string' xmlns:c='http://www.w3.org/2001/XMLSchema'>"+ pAccountId +"</b:anyType>" +
      "</a:Values>" +
    "</a:ConditionExpression>" +
  "</a:Conditions>" +
  "<a:FilterOperator>And</a:FilterOperator>" +
  "<a:Filters />" +
"</a:FilterExpression>" +
          "</a:Filters>" +
        "</a:Criteria>" +
        "<a:Distinct>false</a:Distinct>" +
        "<a:EntityName>account</a:EntityName>" +
        "<a:LinkEntities />" +
        "<a:Orders />" +
        "<a:PageInfo>" +
          "<a:Count>0</a:Count>" +
          "<a:PageNumber>0</a:PageNumber>" +
          "<a:PagingCookie i:nil='true' />" +
          "<a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount>" +
        "</a:PageInfo>" +
        "<a:NoLock>false</a:NoLock>";

        var childAccounts = XrmServiceToolkit.Soap.RetrieveMultiple(query);

        alert(childAccounts[0].attributes['name'].value);
        alert(childAccounts[0].attributes['accountid'].id);
}

回答1:

For your piece of code you can use something like this, because is going to give you the id of the account.

alert(childAccounts[0].id);

You can use the debug and put a watch to get expression of the value.