RE: Inventory Transfer – Dynamic Mode Failure

Hello,

I am writing a script to do mass inventory transfer from one location to another. Below is my script which should work and I don’t see anything wrong. However, I am getting an error to “Enter at least one line to save the transaction” but the line I am entering isn’t working.

Advanced Inventory Feature is NOT enabled – Inventory Detail doesn’t apply

Any help would be very much appreciated

/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScript public
*/
define([‘N/search’, ‘N/record’, ‘N/runtime’],
function (search, record, runtime) {
functionexecute() {
varsavedSearchParam=runtime.getCurrentScript().getParameter({ name :’custscript_item_saved_search’});
varmasterLocationParam=runtime.getCurrentScript().getParameter({ name :’custscript_item_location’ });
vartransferDept=runtime.getCurrentScript().getParameter({ name :’custscript_department’ });
varbin=runtime.getCurrentScript().getParameter({ name :’custscript_bin’});
varresults=search.load({ id :savedSearchParam });
varfilters=results.filters;
varcolumns=results.columns;
varitemSearch=search.create({
type :search.Type.ITEM,
filters :filters,
columns :columns
});
varitemRs=itemSearch.run().getRange({ start :0, end :1000 });
if (itemRs)
{
log.debug(itemRs.length+’ Items to transfer.’);
for (vari=0; i<itemRs.length; i+=1)
{
try
{
varorgLocation=itemRs[i].getValue({ name :’inventorylocation’});
varorgQuantity=itemRs[i].getValue({ name :’binonhandcount’});
varitemId=itemRs[i].getValue({ name :’internalid’});
varsourceBin=itemRs[i].getValue({ name :’binnumber’});
if ( itemId==’18695′ ) {
log.debug(‘Starting Bin Transfer’,’…..’);
log.debug(‘Transferring ‘+itemId+’ To ‘+masterLocationParam+’ From ‘+orgLocation, ‘Quantity: ‘+orgQuantity);
varinventoryXfer=record.create({
type :record.Type.INVENTORY_TRANSFER,
isDynamic :true
});
inventoryXfer.setValue({ fieldId :’location’, value :orgLocation });
inventoryXfer.setValue({ fieldId :’department’, value :transferDept});
inventoryXfer.setValue({ fieldId :’transferlocation’, value :masterLocationParam });
inventoryXfer.selectNewLine({ sublistId :’inventory’});
inventoryXfer.setCurrentSublistValue({
sublistId:’inventory’,
fieldId :’item’,
value :itemId,
});
inventoryXfer.setCurrentSublistValue({
sublistId:’inventory’,
fieldId :’adjustbyqty’,
value :orgQuantity,
})
inventoryXfer.setCurrentSublistValue({
sublistId:’inventory’,
fieldId :’quantityonhand’,
value :orgQuantity,
})
inventoryXfer.setCurrentSublistValue({
sublistId:’inventory’,
fieldId :’tobins’,
value :bin,
})
// inventoryXfer.setCurrentSublistValue({
// sublistId: ‘inventory’,
// fieldId : ‘quantity’,
// value : orgQuantity,
// ignoreFieldChange: true
// })
inventoryXfer.commitLine({ sublistId:’inventory’});
inventoryXfer.save();
}
}
catch (error)
{
log.debug(‘error’, error);
log.debug(‘error’, error.message);
log.debug(‘stack’, error.stack);
}
}
}
}
return {
execute:execute
};
});

                
rmlakhani Rookie Asked on December 10, 2019 in SuiteScript.
Add Comment
1 Answers

It is very hard to read you code with all those html tags.
Can you please paste is a normal code?

Also, have you tried created the same inventory transfer in the UI to see if it works?

Rookie Answered on December 22, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.