
State 1:

Custom created Email template:
Workflow Script:
/**
* @NApiVersion 2.x
* @NScriptType WorkflowActionScript
*/
define(['N/record', 'N/search'], function (record, search) {
function onAction(scriptContext) {
try {
var salesOrder = scriptContext.newRecord;
var customerId = salesOrder.getValue({ fieldId: 'entity' });
var recId = salesOrder.id;
log.debug("Test", salesOrder + " " + customerId + " " + recId)
var transactionSearchObj = search.create({
type: "transaction",
settings: [{ "name": "consolidationtype", "value": "ACCTTYPE" }],
filters:
[
["mainline", "is", "T"],
"AND",
["cogs", "is", "F"],
"AND",
["taxline", "is", "F"],
"AND",
["shipping", "is", "F"],
"AND",
["name", "anyof", customerId],
"AND",
["internalid", "noneof", recId]
],
columns:
[
search.createColumn({ name: "internalid", label: "Internal ID" })
]
});
var searchResultCount = transactionSearchObj.runPaged().count;
log.debug("searchResultCount", searchResultCount)
if (searchResultCount > 0) {
return 0
}
return 1
} catch (e) {
log.error('Error @ onAction', e);
return 0
}
}
return {
onAction: onAction
};
});
This script needs to be deployed so that it can be accessed in the workflow.