Hi, I have a custom record that looks similar to t...
# suitescript
b
Hi, I have a custom record that looks similar to the table attached here. The unit column is a look up from the UOM table. I am trying to run a search that if I give the UNIT then I am returned with the internal ID. This is an extract of my script so far. The itemunitID and itemunitTx are pulling back the correct values. But I can't pull back the internal id of the custom record. So itemunitId could be 12, and itemunitTx could be 'Gram' and I would want to return 2 which is the internal ID in this table. Any ideas where I am going wrong?
Copy code
let itemunit = search.lookupFields({ type: 'item', id: itemValue, columns: ['stockunit'] });
let itemunitID = itemunit.stockunit[0].value;
let itemunitTx = itemunit.stockunit[0].text;
        var customRecordTypeId = 'customrecord_ukr_uom';
        var SfieldId = 'custrecord_eng_unit';
        var mySearch = search.create({
                type: customRecordTypeId,
                filters: [
                    [SfieldId, search.Operator.IS, itemunitID ]
                ],
                columns: [
                    'internalid',
                    SfieldId
                ]
            });

var results = mySearch.run().getRange({ start: 0, end: 100 });
if (results.length > 0) {
                log.audit('Search Results', 'Found ' + results.length + ' matching records.');
                results.forEach(function(result) {
                    log.debug('Record Found', {id: result.getValue('internalid'),value: result.getText(SfieldId)});
                });
} else { log.audit('Search Results', 'No matching records found.'); }
a
you don't use .getValue('internalid'), you also don't need to include it as column i don't think? its just always there. its just .id
Copy code
log.debug('Record Found', {id: result.id,value: result.getText(SfieldId)});
✅ 1
b
Thanks! 🙂 That sorted that part of the script.. just have another issue further down to spend a while scratching my head over.
😂 1
👍 1