I'm trying to delete a record that is related to the current record loaded using a workflow action script. I've seen other answers to similar questions saying that I can find the internal ID of the related record with a search using the value in the key field as the search parameter. Problem: The N/search module is not available in a workflow action script, which is where I'm currently coding.
To make the question more concrete, my user has pulled up a general ledger account record ('account'), and they're going to delete it. I have an NS bundle that functions as an integrator with a 3rd party piece of software. The NS bundle has a value transformation table that maps the NS account codes to the 3rd party software codes. Each value transformation lives in a custom record ('icvt') created by the bundle, and I need the value transformation record deleted. I was hoping to use N/search to look up the icvt record, but I CAN'T USE SEARCH in a workflow action script.
Help.
Edit: Just realized I think I misunderstood the documentation, and that N/search is available, so my error must be somewhere else.
Edit to add code. This is the search code I was using before I realized the module wasn't available to me:
/**
*@NApiVersion 2.x
* @NScriptType WorkflowActionScript
*/
// Deletes Value Transform related to account deleted.
define(['N/record', 'N/search', 'N/log'], function (record, search, log) {
function wfDeleteICVT(scriptContext) {
var deleted_account = scriptContext.newRecord;
var da_internalID = deleted_account.getValue("id");
var v_da_internalID = da_internalID.toString();
var mySearch = search.create({
type: 'icvt',
filters: [
search.createFilter({
name: 'sourcevalue',
operator: search.Operator.IS,
values: v_da_internalID
})
]
});
//log.debug(v_da_internalID)
var myResultSet = mySearch.run();
var myResultRange = myResultSet.getRange(0,1);
log.debug({title: myResultRange.length, details: myResultSet})
var deleted_icvt = mySearch[0];
var di_icvt = deleted_icvt.id;
deleted_icvt.delete({
type: 'icvt',
id: di_internalID
});
}
return {
onAction : wfDeleteICVT
}
});