我从 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/