1

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.

jasonscript
  • 6,039
  • 3
  • 28
  • 43
Aritra B
  • 1,726
  • 6
  • 29
  • 45

1 Answers1

2

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/

jasonscript
  • 6,039
  • 3
  • 28
  • 43
Anish
  • 588
  • 6
  • 21