If you have some fields that need to be imported but you don't want the user to edit the field, you can use a Data Hook like this to prevent editing. The following Data Hook is formatted for Portal 2.0.
// container for values of firstName field that shouldn't be edited
let fnameNoEdit = [];
importer.registerRecordHook(async (record, index, mode) => {
let out = {};
// store every value of field as it's loaded into Flatfile and
// show user that it shouldn't be edited
if (record.firstName && mode === "init") {
out.firstName = {
value: record.firstName,
info: [{ message: "This field can not be edited", level: "info" }]
};
fnameNoEdit[index] = out.firstName;
}
// If user does change the field, reset the value to what it was
if (record.firstName && mode === "change") {
if (record.firstName !== fnameNoEdit[index].value) {
out.firstName = {
value: fnameNoEdit[index].value,
info: [{ message: "This field can not be edited", level: "warning" }]
};
}
}
return out;
});
Comments
0 comments
Please sign in to leave a comment.