D365 JavaScript使用查找,选项集和资金字段创建新记录

时间:2018-07-26 17:50:42

标签: javascript dynamics-crm dynamics-crm-2011 dynamics-crm-2013 dynamics-365

我正在尝试通过从JavaScript调用SDK.REST.CreateRecord函数来创建新记录。下面是我尝试不做任何改进的代码段-

function CreateProspect(QuoteId) {
  SDK.REST.retrieveRecord(QuoteId, "brm_quote", "brm_quotedexipt,brm_inceptiondate,brm_Client", null, function (result) {
     var prospect= {
       brm_inceptiondate: getFomattedDate(result.brm_inceptiondate),
       brm_clientName: {
         Id:result.brm_Client.Id, 
         LogicalName :"brm_ClientName"
       },//lookup fails
       brm_currentAmount:{ 
         Value:result.brm_quotedexipt.Value
       },//moneyfield fails
       brm_type: {Value:17200001} //optionset field Fails
    }

    SDK.REST.createRecord(prospect,"brm_prospect", function(){
      alert('New prospect created')
    },function (error) { 
      alert(error.message); 
    })
  }, function (error) { 
    alert(error.message); 
  });
}

需要一些帮助,以找到向javascript对象添加 lookup / optionset decimal 属性的正确方法,以便CRM可以解释从SDK的Create方法读取它时正确显示它。

对此有任何帮助,我们深表感谢。谢谢。

1 个答案:

答案 0 :(得分:1)

要使用LookUp,请使用此

// Set a lookup
account.PrimaryContactId = {
  Id: "GUID",               // ID of existing Contact. Must be a Guid
  LogicalName: "contact", 
  Name: "contact name"      // Provide Existing Contact Name (optional)
};

// Set a money value
account.Revenue = { Value: "2000000.00" };

// Set a picklist value
account.PreferredContactMethodCode = { Value: 2 };

有关更多详细信息:https://arunpotti.wordpress.com/2014/04/14/rest-create-example/