Or use a map/reduce
# general
p
Or use a map/reduce
s
can you please an example
p
Please re-ask in the suitescript channel with specifics surrounding what you're actually trying to do, what your code currently does, and any relevant code samples. You can't ask very broad questions and expect a sensible constructive answer. Help us to help you?
s
define(["N/record", "N/log", "N/https", "N/search", "N/format", "N/http", "N/runtime", "N/ui/serverWidget","N/redirect"], function(record, log, https, search, format, http, runtime, serverWidget,redirect) { function beforeSubmit(context) { setHsnCode(context); } function setHsnCode(context){ try{ if (context.type !== context.UserEventType.DELETE) { var rec=context.newRecord; var lc=rec.getLineCount('item'); for (var i=0; i<lc; i++){ var item= rec.getSublistValue({ sublistId:'item', fieldId:'item', line:i }); itemSavedSearch1(item,rec,i) } } } catch(e){ log.debug(e.name,e.message); } } function itemSavedSearch1(item,rec,i){ var itemSearchObj = search.create({ type: "item", filters: [ ["type","anyof","Subtotal","Service","OthCharge","Payment","NonInvtPart","Markup","Kit","Group","InvtPart","Discount","Description"], "AND", ["internalid","anyof",item] ], columns: [ search.createColumn({name: "internalid", label: "Internal ID"}), search.createColumn({name: "custitem_in_hsn_code", label: "HSN or SAC Code"}), search.createColumn({name: "custitem_in_nature", label: "Nature"}) ] }); var internalId; var hsnCode; var nature; var columns=itemSearchObj.columns; var searchResultCount = itemSearchObj.runPaged().count; log.debug("itemSearchObj result count",searchResultCount); itemSearchObj.run().each(function(result){ internalId=result.getValue(columns[0]); log.debug('internalId',internalId); hsnCode=result.getValue(columns[1]); log.debug('hsnCode',hsnCode); nature=result.getValue(columns[2]); log.debug('nature==>',nature); var k=0; if (searchResultCount > 0){ rec.setSublistValue({ sublistId: 'item', fieldId: 'custcol_in_hsn_code', value: hsnCode, line:i, ignoreFieldChange: true }); rec.setSublistValue({ sublistId: 'item', fieldId: 'custcol_in_nature_of_item', value: nature, line:i, ignoreFieldChange: true }); return true; } }); return hsnCode; } return { beforeSubmit: beforeSubmit }; });
Trying to populate the HSNcode from the item master . There are more than 500 lines on per invoice transaction. So if I am running this code I am getting this error
p
you don't need any of this code. you can source the item value on to the line automatically...
s
but this is a standard field
s
@SG This is the trigger point for you to learn to use objects, you need to define an item array, say itemArr, store all the item ids there. Whack it in one search, use the search, iterate the results and build a nice object for you to refer to Then you iterate the object say.. for (var item in itemObj)