java - 通过 SOAP/Java 在 MS Dynamics CRM 2011 中创建产品

标签 java soap dynamics-crm-2011 dynamics-crm-online

我从 crm.dynamics.com/XRMServices/2011/Discovery.svc?wsdl 和 crm.dynamics.com/XRMServices/2011/Organization.svc?wsdl 架构生成了所有必需的 java 类。

我使用 LiveId 在 CRM 中进行了身份验证。

现在我需要在产品目录中创建产品。这是相关代码:

Entity newEntryInfo = new Entity();

AttributeCollection collection = new AttributeCollection();
addAttribute(collection, "name", "Tama Starclassic Performer");
addAttribute(collection, "productnumber", "1");

addAttribute(collection, "price", createMoney("100.0"));
addAttribute(collection, "isstockitem", Boolean.TRUE);
addAttribute(collection, "statuscode", 1);

newEntryInfo.setAttributes(collection);
newEntryInfo.setLogicalName("product");

Guid productGuid = serviceStub.create(newEntryInfo);

private void addAttribute(AttributeCollection collection, String key, Object value) {
    KeyValuePairOfstringanyType values = new KeyValuePairOfstringanyType();
    values.setKey(key);
    values.setValue(value);

    collection.addKeyValuePairOfstringanyType(values);
}

执行显示错误“单位计划 ID 丢失。”

看来我需要为新产品提供“单位组”和“默认单位”。

问题:我如何设置这些值?我应该使用相关实体(如何创建它)还是属性(如何创建它)

最佳答案

由于它是表单上的查找,因此您应该能够使用 EntityReference 设置值。

使用您的方法:

addAttribute(collection, "fieldName", new EntityReference("entityName", new Guid("id"))

地点:

  • fieldName 是您要填充的字段的架构名称
  • entityName 是您想要填充字段的实体的架构名称
  • id 是记录的 Guid,与 entityName 类型相同。

将其放入上下文中(我碰巧知道模式名称)。

//Create a new contact first
Entity contact = new Entity("contact");
contact["lastname"] = "Wood";

Guid contactId = service.Create(contact);

//Create an incident/case which links to that new contact
Entity incident = new Entity("incident");
incident["customerid"] = new EntityReference("contact", contactId)
service.Create(incident)

另一方面,您使用如此冗长的代码风格是否有特殊原因?实体类有一个链接到底层属性字典的索引。它更直接一些。

如果您正在寻找更多示例,请查看:Use the Late Bound Entity Class in Code

关于java - 通过 SOAP/Java 在 MS Dynamics CRM 2011 中创建产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17081217/

相关文章:

java - 许多带有mbeans的java进程,如何管理jmx端口

javascript - CRM 2011 - 联系人表单加载无法在生日字段更改时分配给函数结果

java - 如何将入站和出站 SOAP 处理程序相互关联

dynamics-crm-2011 - 如何在CRM中进行相对补码查询?

php - 使用 Web 服务访问 Dynamics CRM 2011

java - 具有自定义集合属性的 JPA 投影

java - 如何将 arrayList 元素转换为二维数组?

java - 只读模式下不允许写操作(FlushMode.MANUAL) : with grails hibernate

java - 调用 SOAP 服务时出现 INVALID_WSDL 错误

java - Spring ws - 每个属性都返回 null