0

使用 Microsoft CRM 2011 在线并使用 web 服务,我在 Main.java 中使用由 webservices 调用创建的 OrganizationServiceStub 类的以下方法。检索到的记录的输出为 -1 有人可以帮我解决我的问题。我想检索名称以“Tel”开头的帐户而不提供帐户 ID。我可以看到数据存在于 CRM 中。谢谢

public static void getAccountDetails(OrganizationServiceStub service, ArrayOfstring fields)
{
    try{
    ArrayOfanyType aa = new ArrayOfanyType();   
    aa.setAnyType(new String[] {"Tel"});

    ConditionExpression condition1 = new ConditionExpression();
    condition1.setAttributeName("name");


    condition1.setOperator(ConditionOperator.BeginsWith);
    condition1.setValues(aa);

    ArrayOfConditionExpression ss = new ArrayOfConditionExpression();
    ss.setConditionExpression(new ConditionExpression[] {condition1});

    FilterExpression filter1 = new FilterExpression();
    filter1.setConditions(ss);

    QueryExpression query = new QueryExpression();
    query.setEntityName("account");

    ColumnSet cols = new ColumnSet();
    cols.setColumns(fields);
    query.setColumnSet(cols);

    query.setCriteria(filter1);

    RetrieveMultiple ll = new RetrieveMultiple();
    ll.setQuery(query);

    RetrieveMultipleResponse result1 = service.retrieveMultiple(ll);

    EntityCollection accounts = result1.getRetrieveMultipleResult();

    System.out.println(accounts.getTotalRecordCount());        
} 
catch (IOrganizationService_RetrieveMultiple_OrganizationServiceFaultFault_FaultMessage e) {
    logger.error(e.getMessage());
    e.printStackTrace();
} 
catch (RemoteException e) {
    logger.error(e.getMessage());
    e.printStackTrace();
}
}
4

2 回答 2

3

对于 Java,包含此代码片段适用于上述问题

ArrayOfanyType aa = new ArrayOfanyType();   
aa.setAnyType(new String[] {"555"});
ConditionExpression condition1 = new ConditionExpression();

condition1.setAttributeName("telephone1");

condition1.setOperator(ConditionOperator.BeginsWith);
condition1.setValues(aa);

ArrayOfConditionExpression ss = new ArrayOfConditionExpression();
ss.setConditionExpression(new ConditionExpression[] {condition1});

FilterExpression filter1 = new FilterExpression();
filter1.setConditions(ss);

QueryExpression query = new QueryExpression();
query.setEntityName("account");

PagingInfo pagingInfo = new PagingInfo();
pagingInfo.setReturnTotalRecordCount(true);

query.setPageInfo(pagingInfo);

OrganizationServiceStub.ColumnSet colSet = new OrganizationServiceStub.ColumnSet();
OrganizationServiceStub.ArrayOfstring cols = new OrganizationServiceStub.ArrayOfstring();

cols.setString(new String[]{"name", "telephone1", "address1_city"});

colSet.setColumns(cols);

query.setColumnSet(colSet);
query.setCriteria(filter1);

RetrieveMultiple ll = new RetrieveMultiple();
ll.setQuery(query);

OrganizationServiceStub.RetrieveMultipleResponse response = serviceStub.retrieveMultiple(ll);
EntityCollection result = response.getRetrieveMultipleResult();
ArrayOfEntity attributes = result.getEntities();

Entity[] keyValuePairs = attributes.getEntity();

for (int i = 0; i < keyValuePairs.length; i++) {
    OrganizationServiceStub.KeyValuePairOfstringanyType[] keyValuePairss = keyValuePairs[i].getAttributes().getKeyValuePairOfstringanyType();
    for (int j = 0; j < keyValuePairss.length; j++) {
         System.out.print(keyValuePairss[j].getKey() + ": ");
         System.out.println(keyValuePairss[j].getValue());
    }
}
于 2013-07-16T09:17:07.000 回答
0

不确定您的EntityCollection对象与 SDK 中的 .Net 版本有多相似,但是您需要ReturnTotalRecordCount在 .Net 中的查询的 PagingInfo 中指定该TotalRecordCount属性才能具有值。你不能改为检查accounts.Entities.Count吗?

注意:我也不是 Java 人...

于 2012-09-17T13:28:26.807 回答