Creating Item Receipts from POs via SuiteScript - netsuite

I'm in the process of creating a module to handle multi-PO consolidated shipments (fx imports) and writing a script to receive multiple POs with landed costs per line.
I'm using SuiteScript API 1.0
However, when I create the Item Receipt record (and include the PO# in the createdfrom field to create the link from IR to PO, during the process of copying the PO lines to the IR lines, I'm getting constant SSS_INVALID_SUBLIST_OPERATION errors.
The code in question is below:
// ** set body fields
receiptRec.setFieldValue('location',purchRec.getFieldValue('location'));
receiptRec.setFieldValue('entity',purchRec.getFieldValue('entity'));
receiptRec.setFieldValue('createdfrom',purchRec.getFieldValue('internalid'));
receiptRec.setFieldValue('currency',purchRec.getFieldValue('currency'));
receiptRec.setFieldValue('exchangerate',purchRec.getFieldValue('exchangerate'));
receiptRec.setFieldValue('isbasecurrency',purchRec.getFieldValue('isbasecurrency'));
receiptRec.setFieldValue('exchangerate',purchRec.getFieldValue('exchangerate'));
receiptRec.setFieldValue('landedcostperline','T');
log ('Receipt Record:'); log( receiptRec );
// ** copy item lines
var POlines = purchRec.getLineItemCount('item');
for ( line=1 ; line<=POlines; line++) {
var fulfill = purchRec.getLineItemValue('item','fulfillable',line); log('Fulfill?? '+fulfill)
if (fulfill == 'T') {
log('Fill From PO Line #'+line);
receiptRec.selectNewLineItem('item'); log('Debug 1');
receiptRec.setCurrentLineItemValue('item','item',purchRec.getLineItemValue('item','item',line)); log('Debug 2');
receiptRec.setCurrentLineItemValue('item','itemreceive','T',line); log('Debug 3');
receiptRec.setCurrentLineItemValue('item','quantity',purchRec.getLineItemValue('item','quantity',line)); log('Debug 4');
receiptRec.setCurrentLineItemValue('item','rate',purchRec.getLineItemValue('item','rate',line)); log('Debug 5');
receiptRec.setCurrentLineItemValue('item','taxcode',purchRec.getLineItemValue('item','taxcode',line)); log('Debug 6');
receiptRec.setCurrentLineItemValue('item','units',purchRec.getLineItemValue('item','units',line)); log('Debug 7');
receiptRec.commitLineItem('item'); log('Debug 8');
}
}
The error is triggering at the selectNewLineItem('item') point.
receiptRec is the newly created itemreceipt record.
purchRec is the existing purchase order record.
What am I missing here?

You cannot "create" a new Item Receipt record in Netsuite. You need to "transform" a Purchase Order into an Item Receipt using nlapiTransformRecord('purchaseorder', purchaseorderid, 'itemreceipt'). This will automatically copy all the line items, and then you can iterate through them to change quantities or remove lines completely, however you cannot add new lines.
See this link in the documentation for more information.

Related

Applying logic to button Make Copy - Netsuite

I just started with Netsuite and Suitescript 2.1. I am wondering if I can apply any logic to the "Make Copy" button via suitescript.
The make copy button is on the opportunity > sublist Item > Line item.
Examples of what I want to do:
Reset certain fields of the copied line
Fill in certain fields of the copied line (with a certain logic
behind it)
I already found a solution. I use the validateLine function. When making a copy of a lineitem in Netsuite the lineitem field: "line" has an empty string value until the line is created by clicking the "Add" button or clicking outside of the copied lineitem. I will check if that field is empty, if yes it means the line is a copy. Afterwards I can also set a custom field isCopy = true.
const lineIsCopied = () => {
let lineNumber = opportunity.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'line'
});
if (lineNumber) {
//linenumber is existing this means line is not a copy
return false;
} else {
//linenumber is empty this mean line is a copy
return true;
}
};
Try the 'validateInsert' within a Client Script.
Make sure your function return 'true' for a valid insert, otherwise any insert for any sublist won't succeed.

NetSuite SuiteTalk Item Fulfillment Error - VALID_LINE_ITEM_REQD

Any suggestions are greatly appreciated!
The sales orders can have 50-100 lines. Each SO will have multiple item fulfillments. When we create the IF through SuiteTalk, we don't know which lines are already fulfilled or which lines are partially fulfilled.
When I create the soap, I am overriding the item list.
The code works fine if there is only 2 items on the sales order and all lines are being fulfilled.
The trouble arises when another process has added / deleted items on the sales order thus causing an order with 5 lines to have soLines such as 1, 45, 245, 300 & 301. If I am trying to fulfill line 245, I will receive VALID_LINE_ITEM_REQD.
Would anyone have suggestions on what needs to be initialized?
Thank you in advance,
Bill
Below is a sample request/response.
Request
<record xmlns:q1="urn:sales_2020_1.transactions.webservices.netsuite.com" xsi:type="q1:ItemFulfillment" externalId="mrk-so-2446425">
<q1:createdFrom internalId="2446425"/>
<q1:shippedDate>2020-12-25T06:00:00Z</q1:shippedDate>
<q1:shipStatus>_shipped</q1:shipStatus>
<q1:tranDate>2020-12-25T06:00:00Z</q1:tranDate>
<q1:generateIntegratedShipperLabel>false</q1:generateIntegratedShipperLabel>
<q1:itemList>
<q1:item>
<q1:location internalId="308"/>
<q1:quantity>1</q1:quantity>
<q1:item internalId="82198"/>
<q1:orderLine>101</q1:orderLine>
</q1:item>
</q1:itemList>
</record>
Response
<writeResponse>
<platformCore:status xmlns:platformCore="urn:core_2020_1.platform.webservices.netsuite.com" isSuccess="false">
<platformCore:statusDetail type="ERROR">
<platformCore:code>VALID_LINE_ITEM_REQD</platformCore:code>
<platformCore:message>You must have at least one valid line item for this transaction.</platformCore:message>
</platformCore:statusDetail>
</platformCore:status>
<baseRef xmlns:platformCore="urn:core_2020_1.platform.webservices.netsuite.com" type="itemFulfillment" xsi:type="platformCore:RecordRef" externalId="mrk-so-2446425"/>
</writeResponse>
Did you start your item fulfillment with an initialize call?
ItemFulfillmentItem has a field 'orderLine'.
This matches with the SalesOrderItem 'line' field.
If what you actually want to fulfill can be calculated from the SO information then I just do a reverse loop through the fulfillment lines, using the orderLine value to key into the SalesOrder and remove any fulfillment lines that shouldn't be on this fulfillment.
You must have at least one valid line item for this transaction
This is cause for a lot reasons:
That line (item) doesn´t exists in this SO
That item doesn´t have available quantity (all backordered)
that line is closed
wrong internalid for the item
after you made the first fulfillment review your SO (partially fulfillment) and verify you remant lines
After you transform your SO to fulfillment
var itemFulfillMent = record.transform( {
fromType: context.createdfrom.recordType,
fromId: context.createdfrom.id,
toType: 'itemfulfillment',
isDynamic: true,
} );
make a array with (line, item)
var itemsPosition = {};
for ( var i = 0; i < itemFulfillMent.getLineCount( 'item' ); i ++ ) {
itemsPosition[ itemFulfillMent.getSublistValue( 'item', 'item', i ) ] = i;
}
in the itemsPosition you will now know line of your item.

How I can use Autonumber in new screen multiple users in Acumatica?

I have a custom screen in Acumatica with autonumber, but only one user can use at the same time. How can get screen multiuser?
In Sales Order/Payment and Applications I have a tab('COMPLEMENTOS'), in this tab you can add a new complement in other screen. This screen have a field, 'No. Complemento' is Autonumber, the autonumber is generated correctly but if two person are in the same screen at the same time, one of them is saved correctly but the other try to save with the same number that was already used and send an error 'Another Process has updated the CPSetup record. Your changes will be lost'. How I can work with two or more screens at the same time.
if (cache.GetStatus(row) == PXEntryStatus.Inserted)
{
AutoNumberAttribute.SetLastNumberField<COPago.cOPagoCD>(cache, row,
typeof(CPSetup.returnLastDocRefNbr));
if (row.RefNbrPago != null)
{
AutoNumberAttribute.SetPrefix<COPago.cOPagoCD>(cache, row, "REP");
}
}
The actual error is 'Another Process has updated the CPSetup record. Your changes will be lost'
I would like to kwon how I can generate correctly autonumber with the same screen with two or more users at the same time.
When you generate next nunber probably you store it on a field on Numbering Sequence. We call it LastNumber.
When you update the LastNumber field (with next number) on Numbering Sequence you need to use an SQL transaction
using (PXTransactionScope ts = new
PXTransactionScope())
{
//Update LastNumber with next number
// persist cache
ts.Complete();
}

NetSuite - using nlapiCopyRecord function

I am generating an invoice when the original invoice is overdue by a certain time period. I want to know if we can use the nlapiCopyRecord to make a copy of the original invoice but allow us to insert a new line that will replace the old line item? I haven't found any sample to show how this is done.
Thanks.
Edit 1:
var new_inv = nlapiCopyRecord('invoice', internal_id,
{
item : 66,
amount: amount,
description: 'TEST'
});
var copiedId = nlapiSubmitRecord(new_inv);
return copiedId;
Above code fails in my scheduled script. You have entered an invalid default value for this record initialize operation.
I would like to override the line item on the newly copied invoice
Yes that is possible, just like if you copy a record in the UI you can modify the copy. You also need to remember that you need to save the record object after you have copied it.
Why are you doing this? If you are trying to charge a late fee you'd probably be better off by adding an expense line to the original invoice record. If you don't have expenses turned on then you could add an other "Other Charge for Sale"
If your code is running server side then:
var invRec = nlapiLoadRecord('invoice', internal_id);
var chargeIndex = invRec.getLineItemCount('item') + 1;
// don't think you need this for the end position invRec.insertLineItem('item', chargeIndex);
invRec.setLineItemValue('item', 'item', chargeIndex, charge_item_id);
invRec.setLineItemValue('item', 'rate', chargeIndex, amount);
invRec.setLineItemValue('item', 'amount', chargeIndex, amount);
nlapiSubmitRecord(invRec);
OR if you use an expense
var invRec = nlapiLoadRecord('invoice', internal_id);
invRec.insertLineItem('expense', 1);
invRec.setLineItemValue('expense', 'account', 1, penalty_account);
invRec.setLineItemValue('expense', 'amount', 1, amount);
invRec.setLineItemValue('expense', 'memo', 1, 'TEST');
nlapiSubmitRecord(invRec);

Issue with List Apply in NetSuite

Unable to find a matching line for sublist apply with key: [doc,line] and value: [5489377,1].
I'm seeing this error when I try to update an apply list on a NetSuite transaction object. The "doc" is the internal ID of the object, and the line number seems to correspond to a line number on the object.
Why is this happening? Can't seem to find a solution.
This works for applying a credit memo to a particular invoice. invId is the internalid of the invoice record:
function applyPayment(creditMemo, payAmount, invId){
var didApply = false;
creditMemo.setFieldValue('autoapply', 'F');
if(payAmount === null) payAmount = creditMemo.getFieldValue('amountremaining');
for(var i = 1; i<=creditMemo.getLineItemCount('apply'); i++){
if(invId == creditMemo.getLineItemValue('apply', 'doc', i)){
didApply = true;
creditMemo.setLineItemValue('apply', 'apply', i, 'T');
creditMemo.setLineItemValue('apply', 'amount',i, payAmount);
}else if('T' == creditMemo.getLineItemValue('apply', 'apply', i)) creditMemo.setLineItemValue('apply', 'apply', i, 'F');
}
if(didApply) nlapiSubmitRecord(creditMemo);
}
We were getting this error with the Chargebee-Netsuite integration and the solution was to open the corresponding Accounting Period in Netsuite and rerun the sync.
Like you mentioned, the first number[5489377,1] is the Netsuite internal ID of the affected document. If you navigate to the document in Netsuite and it has a padlock this could be the reason Locked document
Open the Accounting Period for the affected document and rerun the sync. setup/accounting/manage accounting periods Manage accounting periods

Resources