简体   繁体   English

通过Java API激活和取消激活Dynamics CRM中的实体

[英]Activating and Deactivating Entities in Dynamics CRM from Java API

I am using the Microsoft Dynamics CRM, using the Java API generated as per their tutorial and SDK downloads. 我使用的是Microsoft Dynamics CRM,使用的是根据其教程和SDK下载生成的Java API。

I can create, delete, and update entities with no problems. 我可以毫无问题地创建,删除和更新实体。

I am now at the stage where I need to set entities to active or inactive. 我现在处于将实体设置为活动或不活动的阶段。

I had thought that the right way to do this was roughly 我以为正确的方法大概是

public void doIt(OrganisationServicesStub stub, OptionSetValue stateValue, OptionSetValue statusValue)
{
    Guid g = new Guid();
    g.setGuid("abc-def-ghijkl");

    Entity updateMe = new Entity();
    updateMe.setId(g);
    updateMe.setLogicalName("ei_teacherdetails");
    AttributeCollection updateCollection = new AttributeCollection();
    updateCollection.addKeyValuePairOfstringanyType(pair("statecode", stateValue));
    updateCollection.addKeyValuePairOfstringanyType(pair("statuscode", statusValue)); 
    updateMe.setAttributes(updateCollection);

    update.setEntity(updateMe);
    stub.update(update);
}

public static KeyValuePairOfstringanyType pair(String key, Object value)
{
    KeyValuePairOfstringanyType attr = new KeyValuePairOfstringanyType();
    attr.setKey(key);
    attr.setValue(value);
    return attr;
}

The above code has been tested and works for updating any attributes except the state/status ones. 上面的代码已经过测试,可用于更新除状态/状态属性外的所有属性。 When I try the above code, however, (ie the code that tries to update the state/status), I get the following error (calling with state/status values of 1 and 2 respectively. I got those values by looking at existing Invalid entries in the CRM dumped through the same api, so I am (almost) certain that they are correct. 但是,当我尝试上述代码(即尝试更新状态/状态的代码)时,出现以下错误(分别以状态/状态值为1和2进行调用。通过查看现有的Invalid获得这些值) CRM中的条目是通过相同的api转储的,因此我(几乎)可以肯定它们是正确的。

org.apache.axis2.AxisFault: 2 is not a valid status code for state code ei_teacherdetailsState.Active

I have noticed that in other languages, there is a SetState request, but I don't find a similar one in Java. 我注意到在其他语言中,有一个SetState请求,但是在Java中找不到类似的请求。

If anyone has been down this path before me, I'd greatly appreciate any assistance you could give. 如果有人在我之前走过这条路,我将非常感谢您能提供的任何帮助。

It turns out that the correct answer is as follows, as best I can tell.... 事实证明,正确的答案如下,据我所知。

private void doIt(OrganizationServiceStub stub, OptionSetValue state, OptionSetValue status)
{
    OrganizationRequest request = new OrganizationRequest();
    request.setRequestName("SetState");

    ParameterCollection collection = new ParameterCollection();
    collection.addKeyValuePairOfstringanyType(pair("State", state));
    collection.addKeyValuePairOfstringanyType(pair("Status", status));
    request.setParameters(collection);

    Guid g = new Guid();
    g.setGuid("abc0def-ghi");
    EntityReference ref = new EntityReference();
    ref.setId(g);
    ref.setLogicalName("ei_teacherdetails");
    collection.addKeyValuePairOfstringanyType(pair("EntityMoniker", ref));

    Execute exe = new Execute();
    exe.setRequest(request);
    stub.execute(exe);
}

Which is pretty obscure, I think. 我认为这很模糊。 Especially I like that there's a parameter called "EntryMoniker". 特别是我喜欢一个名为“ EntryMoniker”的参数。 Anyway, I leave this answer here just in case some other poor soul ends up having to deal with this MS CRM intricacy. 无论如何,我在这里留下了这个答案,以防万一其他可怜的人最终不得不处理这种MS CRM复杂性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM