Dyanamics crm 2015 sp 1, throw exception "Unable to get property 'trim' of undefined or null reference" While setting a lookup value.
- CustomerId have all three properties i.e Id,Name and LogicalName
- Field "new_customerprofileid" is populated too,but setValue() function throw error
- Error location is in global.ashx, there is a line
b.trim
which through the error.
Code:
var Entity = RetrieveEntityById(Id, "SalesOrder");
if (Entity != null) {
var CustomerId = Entity.CustomerId;
if (CustomerId != null)
if (Xrm.Page.getAttribute("new_customerprofileid") != null)
Xrm.Page.getAttribute("new_customerprofileid").setValue([{ id: CustomerId.Id, name: CustomerId.Name, entityType: CustomerId.LogicalName }]);
}
One fix is to place line( .setValue("") ) in try catch block.
var Entity = RetrieveEntityById(Id, "SalesOrder");
if (Entity != null) {
var CustomerId = Entity.CustomerId;
if (CustomerId != null)
if (Xrm.Page.getAttribute("new_customerprofileid") != null)
try {
Xrm.Page.getAttribute("new_customerprofileid").setValue([{ id: CustomerId.Id, name: CustomerId.Name, entityType: CustomerId.LogicalName }]);
} catch (ex) { }
}
Please answer if anybody reach to some other fix for this error.
The system tries to trim the input values but at least one of them was
null
and not a String. I guess this means that one of the values provided in the setValue dictionary is null: eitherCustomerId.Name
orCustomerId.LogicalName
. You might exclude those data sets or you might want to set their value to an empty string.