D365/Ax7 Data Entity error : Results. Field 'Invoice account' must be filled in. Results. validateWrite() failed on data source "Tablename"
Many times while importing data through Entity will get below error message :
Results. Field 'Invoice account' must be filled in. Results. validateWrite() failed on data source "Tablename"
Solution : both steps are necessary to resolve above error
1. Set "Allow edit" and "Allow Edit on create" property to Yes on Entity field level
2. Overide method mapEntityToDataSource() at Entity level and call skipDataSourceValidateField() with true as parameter as shown in below example
public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
super(_entityCtx, _dataSourceCtx);
switch (_dataSourceCtx.name())
{
case dataEntityDataSourceStr(EntityName, EntityName):
switch (_entityCtx.getDatabaseOperation())
{
case DataEntityDatabaseOperation::Insert:
if (this.isFieldSet(fieldNum(TableName, FieldName)))
{
// Without skipping this validation, validateField will fail on the mapped field.
this.skipDataSourceValidateField(fieldNum(TableName, FieldName), true);
}
}
}
}

Comments
Post a Comment