This script allows you to ask the user to correct some fields prior to import in Portal 2.0:
import FlatfileImporter from "@flatfile/adapter";
import $ from "jquery";
import { schemas } from "./schemas";
const { contactSchema } = schemas;
const importer = new FlatfileImporter(
"5fdae7f9-84ca-43bd-b178-2c401871be38",
contactSchema
);
importer.setCustomer({
userId: "19234",
name: "Foo Bar"
});
function handleResults(results) {
constrowtoUpdate=[];
rowtoUpdate[3]={
zipCode: {
value: "123456",
info: [{ message: "This zip code is too long", level: "error" }]
},
phone: {
value: "12345",
info: [{ message: "this is not a valid phone number", level: "error" }]
}
};
importer
.requestCorrectionsFromUser(
"There was an error in post-processing. Please check the phone and zip code fields for errors.",
rowtoUpdate
)
//.then(handleResults)
.then(function(results){
importer.displaySuccess("Thanks for your data.");
$("#raw_output").text(JSON.stringify(results.data,"",2));
})
.catch(function(error){
console.info(error||"window close");
});
console.log(results);
}
$("#launch").click(function () {
importer
.requestDataFromUser()
.then(handleResults)
// .then(function (results) {
// importer.displaySuccess("Thanks for your data.");
// $("#raw_output").text(JSON.stringify(results.data, " ", 2));
// })
.catch(function(error){
console.info(error||"window close");
});
});
Comments
0 comments
Please sign in to leave a comment.