CRM 2013
I am using SDK.REST.js to create a new record of a custom entity using the createRecord function, all according to msdn (http://msdn.microsoft.com/en-us/library/gg334427.aspx)
This worked initially, but now - a couple of weeks later- this isn't. I don't know if the code has been changed but when I am going through it with alerts everything seems just fine..
Basically I create an object with 3 attributes, 1 text and 2 other objects (because its 1 text field and 2 lookup fields in the record that is being created)
If I run the function I get "Internal Server Error: 340. Nullable object must have a value." , and by commenting out the attributes in the object to see what was causing the problem i found that it is one of the object attributes/lookup values and the rest works fine, record gets created when I don't set this lookup value.
This is the code to create the object:
//Get customer lookup information
var customer = new Array();
customer = Xrm.Page.getAttribute("new_customerid").getValue();
if (customer != null) {
var name = customer[0].name;
var id = customer[0].id;
var entityType = customer[0].entityType;
}
//Get current record information
var invoiceId = Xrm.Page.data.entity.getId();
var entityName = Xrm.Page.data.entity.getEntityName();
var invoiceName = Xrm.Page.getAttribute("new_name").getValue();
var newId = invoiceId.replace('{', '');
newId = newId.replace('}', '');
//Create IntegrationTrigger record
var integrationTrigger = {};
integrationTrigger.custom_name = "Sync'ed invoice: " + invoiceName;
integrationTrigger.custom_Invoice =
{
Id: invoiceId,
Name: invoiceName,
LogicalName: entityName
};
integrationTrigger.custom_Customer = {
Id: id,
Name: name,
LogicalName: entityType
};
SDK.REST.createRecord(integrationTrigger, "custom_integrationtrigger", function (integrationTrigger) {
alert("everything went well!")
},
errorHandler);
XrmSvcToolkit.createRecord(integrationTrigger);
The failing attribute that the SDK.REST.createRecord function isn't liking is "IntegrationTrigger.custom_Invoice". By alerting Id, Name and LogicalName for both invoice and customer objects, they look exactly the same and correct. Still - one lookup is getting set properly, not the other..
Does anybody have any idea why? I'm at the end of the rope.