Hi, I need to update the last purchase price on in...
# suitescript
t
Hi, I need to update the last purchase price on inventory item based on location when the purchase order is created, But I am getting error : USER_ERROR:Please enter value(s) for: Item Category ..... See the code below and please help.function updateLastPurchasePrice(type) { try { if (type=='create'){ // we are here only on an update var cnt=nlapiGetLineItemCount('item'); nlapiLogExecution("DEBUG", "cnt: ",cnt); var loc=nlapiGetFieldValue('location'); //var type; for (var i = 1; i <= cnt; i++) { var itemtype=nlapiGetLineItemValue('item', 'itemtype', i); nlapiLogExecution("DEBUG", "type: ",itemtype); if (itemtype=='InvtPart'){ var itemrate=nlapiGetLineItemValue('item', 'rate', i); var itemid=nlapiGetLineItemValue('item', 'item', i); nlapiLogExecution("DEBUG", "itemid: ",itemid); var itemobj=nlapiLoadRecord('inventoryitem',itemid); //nlapiLogExecution("DEBUG", "cnt: ",cnt); var loccnt=itemobj.getLineItemCount('locations'); nlapiLogExecution("DEBUG", "loccnt: ",loccnt); for (var j = 1; j <= loccnt; j++) { var locid=itemobj.getLineItemValue('locations', 'location', j); nlapiLogExecution("DEBUG", "locid: ",locid); if (locid==loc){ itemobj.setLineItemValue('locations', 'lastpurchasepricemli', j,itemrate); break; } } nlapiSubmitRecord(itemobj); //nlapiSubmitField('inventoryitem', itemid, 'lastpurchaseprice',itemrate); } } } } catch (e) { nlapiLogExecution('ERROR', 'error details', (e.name || e.getCode()) + ":" + (e.message || e.getDetails())); } }
s
I don't believe last purchase price is something you can set? Doesn't it automatically get filled out?
t
Got it ... when create receipt on PO it will get filled automatically...one more question. Can I create custom line field on location Sublist on item record
s
I don't believe so, the location sublist is a very weird part of NS.
k
@Tanu while you saving record, just ignore item mandatory fields. Seems like item category is mandatory field. Regarding Second Question: you mean creating field on Location level like as quantity on hand and quantity available, if then create custom field and add it under inventory management subtab.