Skip to content

Instantly share code, notes, and snippets.

@benstjohn
Created July 13, 2018 16:02
Show Gist options
  • Save benstjohn/8484ff95b275fbb70ccc5baa68b3dd72 to your computer and use it in GitHub Desktop.
Save benstjohn/8484ff95b275fbb70ccc5baa68b3dd72 to your computer and use it in GitHub Desktop.
export function Accounts_beforeInsert(item_ob, context) {
if (item_ob.company_id === undefined) {
item_ob.company_id = item_ob.company.replace(/\s+/g, '-');
make_id_thing(item_ob.company_id, function (obj) {
item_ob.company_id = obj;
console.log("how about " + item_ob.company_id);
});
} else {
item_ob.company_id = item_ob.company_id.replace(/\s+/g, '-');
item_ob.company_id = make_id_thing(item_ob.company_id);
}
return item_ob;
}
function make_id_thing(item, callback) {
wixData.query('Accounts')
.eq('company_id', item)
.find()
.then(result => {
//console.log("total count" + result.totalCount);
if (result.totalCount === 0) {
console.log("fresh");
} else {
item = item + "-" + makeid();
}
console.log("new ID" + item);
createProcessLabels(item, function () {
callback(item);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment