2013-06-13 109 views
1

我從crm.dynamics.com/XRMServices/2011/Discovery.svc?wsdl和crm.dynamics.com/XRMServices/2011/Organization.svc生成所有必需的java類?wsdl模式。通過SOAP/Java在MS Dynamics CRM 2011中創建產品

我使用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缺失。」

看起來我需要爲新產品提供「單位組」和「默認單位」。

問題:如何設置這些值?我應該使用相關實體(如何創建它)或屬性(如何創建它)

回答

0

因爲它是在窗體上查找,您應該能夠設置值爲EntityReference

用你的方法,這將是:

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

其中:

  • fieldName是要填充
  • entityName領域的架構名稱是實體的架構名稱你想用
  • 填寫字段
  • idGuid的一條記錄,它是s ame類型爲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