简体   繁体   中英

D365 JavaScript Create a new record with a lookup, optionset and money field

I am trying to create a new record by calling the SDK.REST.CreateRecord function from JavaScript. Below is the code snippet with which I am trying without any improvement -

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); 
  });
}

Need some help to find the correct way to add a lookup / optionset and decimal properties to the javascript object such that CRM can interpret it correctly while reading it from the SDK Create method.

Any help on this much appreciated. Thank you.

To work with LookUp, use this

// 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 };

For more details: https://arunpotti.wordpress.com/2014/04/14/rest-create-example/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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