Reputation: 771
i want to create an search by joining two records using the left outer join in "suitescript 2.0 version"
first record is an standard record (invoice) and the second record is an custom record(contract) both records having common fields namely:class and transaction type,owner.
Invoice Record fields are the Transaction Column fields (class,transaction type,owner) Contract Record Fields are the custom fields(class,transaction,owner)
I have created search for the Invoice Record and based on the search results of the Invoice Record ,I have created the Search on the contract record. my code is giving the correct results but question is "it possible to create an search for two different records using left outer join in SuiteScript 2.0 version?"
//Create Search on Standard Invoice Record
var mySearch = search.create({
type: 'invoice',
columns: ['internalId', 'item', 'line', 'custcol_class', 'custcol_transaction_type', 'custcol_owner', 'amount'],
filters: ['trandate', 'after', '12/15/2015']
});
//Executing the First 100 records on the search result
var searchResult = mySearch.run().getRange(0, 100);
log.debug('Search Length', searchResult.length);
for (var i = 0; i < searchResult.length; i++) {
var lineId = searchResult[i].getValue({
name: 'line'
});
var item = searchResult[i].getValue({
name: 'item'
});
var contractClass = searchResult[i].getValue({
name: 'custcol_class'
});
var transactionType = searchResult[i].getValue({
name: 'custcol_transaction_type'
});
var owner = searchResult[i].getValue({
name: 'custcol_owner'
});
var invoice_id = searchResult[i].getValue({
name: 'internalId'
});
var invoice_amt = searchResult[i].getValue({
name: 'amount'
});
log.debug('Values', 'contractClass:' + contractClass + '-transactionType:' + transactionType + '-owner:' + owner);
if (contractClass != '' && owner != '' && transactionType != '') {
log.debug('create commision', 'item' + item + '-lineId:' + lineId + '-contractClass:' + contractClass + '-transactionType:' + transactionType + '-owner:' + owner);
createCommission(contractClass, transactionType, owner, invoice_id, invoice_amt);
}
}
}
function createCommission(contractClass, transactionType, owner, invoiceId, invoice_amt) {
log.debug('Entry', 'createCommission Initiated');
log.debug('invoice amount..', invoice_amt);
//Creating search on Custom Record Contract
var mySearch = search.create({
type: 'customrecord_contract',
columns: ['internalId', 'custrecord_rec_class', 'custrecord_vendor_fees_formula'],
filters: [
['custrecord_rec_class', 'anyof', contractClass], 'AND', ['custrecor_rec_transaction_type', 'anyof', transactionType], 'AND', ['custrecord__rec_owner', 'anyof', owner], 'AND', ['custrecord__vendor_fees_formula', 'anyof', INRAM_RS_V1]
]
});
}
Thanks in advance
Upvotes: 0
Views: 4296
Reputation: 8847
Unfortunately this is not currently possible with NetSuite.
You will have to settle for writing a function that takes in both sets of results and combines them accordingly. If you use any array utility libraries like lodash, you could use something like _.groupBy
to make the combination simpler.
Upvotes: 3