Good Day, Hi! Can some help me on creating the Inv...
# suitescript
j
Good Day, Hi! Can some help me on creating the Inventory Adjustment line Item. I want to populate my Sales Order item into the Inventory Adjustment Line, so I deployed a button on Sales Order to redirect it to Inventory Adjustment module. I have set the line items, but having a problem on saving the Inventory Adjustment and receiving a Prompt Message: "You must enter at least one line item for this transaction."
message has been deleted
Here's the code i used.
if(type == 'create' && exec_context == 'USERINTERFACE'){
var cfrom_id = scriptContext.request.parameters.cfrom_id;
if(cfrom_id!= ''){
var cfrom_type = scriptContext.request.parameters.cfrom_type;
var cfrom_rec = record.load({
type: cfrom_type,
id: cfrom_id
});
var ia_location = cfrom_rec.getValue('location');
newRecord.setValue('customer', cfrom_rec.getValue('entity'));
newRecord.setValue('subsidiary', cfrom_rec.getValue('subsidiary'));
newRecord.setValue('custbody_itg_created_from_transaction', cfrom_id);
newRecord.setValue('department', cfrom_rec.getValue('department'));
newRecord.setValue('class', cfrom_rec.getValue('class'));
newRecord.setValue('account', 58);
newRecord.setValue('adjlocation', ia_location);
var cfrom_line = cfrom_rec.getLineCount('item');
var productionquantity = 'custcol_prod_quantity_1_entre';
if(cfrom_line>0){
var linedisplay = 0;
for(var x=0; x<cfrom_line; x++){
var item_type = cfrom_rec.getSublistValue('item','itemtype',x);
if(item_type== 'InvtPart'){
var item_id = cfrom_rec.getSublistValue({sublistId : 'item',fieldId : 'item',line : x});
newRecord.setSublistValue({
sublistId : 'inventory',
fieldId : 'item',
line : linedisplay,
value : item_id
});
newRecord.setSublistValue({
sublistId : 'inventory',
fieldId : 'location',
line : linedisplay,
value : ia_location
});
var adjustqty = parseFloat(cfrom_rec.getSublistValue({sublistId : 'item',fieldId : productionquantity,line : x}));
if(adjustqty == ''){
adjustqty = 0;
}
newRecord.setSublistValue({
sublistId : 'inventory',
fieldId : 'adjustqtyby',
line : linedisplay,
value : adjustqty
});
newRecord.setSublistValue({
sublistId : 'inventory',
fieldId : 'units',
line : linedisplay,
value : cfrom_rec.getSublistValue({sublistId : 'item',fieldId : 'units',line : x}),
});
linedisplay++;
}
}
//START FOR RAW MATS
//START FOR RAW MATS
//START FOR RAW MATS
var totalsheets_search = searchRecords('customrecord_hnd_total_sheets',
[
["custrecord_hndts_mainlink","anyof",cfrom_id],
"AND",
["custrecord_hndts_inventory_adjustment","anyof","@NONE@"]
],
[
search.createColumn({name: "custrecord_hndts_total_sheets", label: "Total Sheets"}),
]
);
var totalsheets = 0;
if(totalsheets_search){
if(totalsheets_search.length>0){
totalsheets = parseFloat(totalsheets_search[0].getValue({name:'custrecord_hndts_total_sheets'}))*-1;
}
}
newRecord.setSublistValue({
sublistId : 'inventory',
fieldId : 'item',
line : linedisplay,
value : 4630//ITEM INTERNAL IF OF RAW MATERIAL
});
newRecord.setSublistValue({
sublistId : 'inventory',
fieldId : 'location',
line : linedisplay,
value : ia_location
});
newRecord.setSublistValue({
sublistId : 'inventory',
fieldId : 'adjustqtyby',
line : linedisplay,
value : totalsheets
});
linedisplay++;
//END FOR RAW MATS
//END FOR RAW MATS
//END FOR RAW MATS
}
}
}
b
my advice would be to move all the code to client script
sourcing does not work in before load user event scripts
j
i have already tried it via client script.
but the commitline doesn't work.
if(ctxmode == 'create'){
var cfrom_id = currentRecord.getValue('custbody_itg_created_from_transaction');
if(cfrom_id!= ''){
var cfrom_rec = record.load({
type: 'salesorder',
id: cfrom_id
});
var ia_location = cfrom_rec.getValue('location');
log.debug('PAGEINIT - ia_location',ia_location);
var cfrom_line = cfrom_rec.getLineCount('item');
log.debug('PAGEINIT - cfrom_line',cfrom_line);
var productionquantity = 'custcol_itg_prod_quantity_1_entre';
if(cfrom_line>0){
for(var x=0; x<cfrom_line; x++){
var currIndex = currentRecord.getCurrentSublistIndex({
sublistId: 'inventory'
});
log.debug('currIndex',currIndex);
log.debug('x',x);
var item_type = cfrom_rec.getSublistValue('item','itemtype',x);
//							currentRecord.selectLine({sublistId:'inventory',line:linedisplay});
log.debug('item_type',item_type);
if(item_type == 'InvtPart'){
currentRecord.selectNewLine({sublistId:'inventory'});
var item_id = cfrom_rec.getSublistValue({sublistId : 'item',fieldId : 'item',line : x});
currentRecord.setCurrentSublistValue({
sublistId : 'inventory',
fieldId : 'item',
value : item_id,
});
currentRecord.setCurrentSublistValue({
sublistId : 'inventory',
fieldId : 'location',
value : ia_location,
});
currentRecord.setCurrentSublistValue({
sublistId : 'inventory',
fieldId : 'adjustqtyby',
value : cfrom_rec.getSublistValue({sublistId : 'item',fieldId : productionquantity,line : x}),
});
currentRecord.setCurrentSublistValue({
sublistId : 'inventory',
fieldId : 'units',
value : cfrom_rec.getSublistValue({sublistId : 'item',fieldId : 'units',line : x}),
});
currentRecord.setCurrentSublistValue({
sublistId : 'inventory',
fieldId : 'custcol_hnd_skuline',
value : cfrom_rec.getSublistValue({sublistId : 'item',fieldId : 'custcol_hnd_skuline',line : x}),
});
currentRecord.commitLine({sublistId:'inventory'});
//								NLInvokeButton(getButton('inventory_addedit'))
}
}
}
}
}
i deployed it on page init function.
b
Use forceSyncSourcing to avoid committing the line before sourcing completes
j
got it thanks.
Is it also working on setting the main field values?
b
depends on what you are doing
but the same parameter exists on body fields