RE: How to write script to avoid duplicate record creation before record submit using suitescript 2.0
I want to create a user event script to avoid custom record creation if record is duplicate.
Also this custom record is being attached to another custom record. I have to stop from creating and attaching custom duplicate record.
Please Help!!
const beforeSubmit = (scriptContext) => { let field1 = scriptContext.newRecord.getValue({fieldId: 'custrecord_field1'}); let field2 = scriptContext.newRecord.getValue({fieldId: 'custrecord_field2'});
let existing_record = false;
search.create({ type: 'customrecord_my_record', columns: ['internalid'],
filters: [
['custrecord_field1', search.Operator.IS, field1],
'and',
['custrecord_field2', search.Operator.IS, field2],
]
}).run().each((result) => {
existing_record = true;
return false;
})
if (existing_record) {
throw error.create({...})
}
}