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"

                                    

Root Cause : Allow edit and Allow Edit on create property is NO on table field level SO same property carry forwarded to Entity data source as well

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

Popular posts from this blog

D365/AX7 - Can not rename database - The database could not be exclusively locked to perform the operation