Christopher Cannata
Christopher Cannata

Reputation: 15

Netsuite - Set Line Item Value

I am trying to figure out how to set a custom value item from the value of another field on the item field. I am not getting any errors, but it is not changing the value.

Here is the code:

function validatePOLineItem(type){
   if(type == 'item'){
     for (var i = 0; i <= nlapiGetLineItemCount('item'); i++) {
     // Get the value for amount on the item line
     var amount = nlapiGetCurrentLineItemValue('item', 'amount');
     // Get the value for the PO Amount on the item line
     var po_amount = nlapiGetCurrentLineItemValue('item', 'custcol_po_amount');
     // Set PO Amount equal to Amount on the item line
     nlapiSetCurrentLineItemValue('item', po_amount, amount);
    }
   }
}

Upvotes: 1

Views: 5148

Answers (4)

Aaron Hinni
Aaron Hinni

Reputation: 14716

Looks like you left off the column name you are trying to set. Also, you should just have to update the "current" line…

function validatePOLineItem(type){
  if(type == 'item'){
    var amount = nlapiGetCurrentLineItemValue('item', 'amount');
    nlapiSetCurrentLineItemValue('item', 'custcol_po_amount', amount);
  }
}

Upvotes: 2

Rusty Shackles
Rusty Shackles

Reputation: 2840

Is this a client side script or a user event script? If it is a client side script that is deployed on the validate line event, then you do not need to do a loop. Since the function will trigger every time a line is added. Also you will need to add 'return true' as the last line for the line to be added.

Upvotes: 1

vVinceth
vVinceth

Reputation: 915

Question: Why do you need to have a loop if you are just dealing with the current line item?

Suggested Solution: If you want to achieve it, you can set the Rate equal to 'custcol_po_amount' but this will only work if the quantity is 1 and assuming that the value on 'custcol_po_amount' is accurate.

Upvotes: 0

erictgrubaugh
erictgrubaugh

Reputation: 8847

You cannot manipulate the amount field programmatically. You need to modify the quantity or the rate instead. If you are trying to apply a discount or something like that, then I recommend using NetSuite's Discount Items or Promo Codes mechanisms.

Upvotes: 0

Related Questions