This is frustrating, doing something in suitescrip...
# suitescript
r
This is frustrating, doing something in suitescript and running client side. If I run the following in the browser console, it works, but when I run the client script I get "sourceRecord.setSublistValue is not a function" on the line for the 'itemreceive' This works in the browser and I'm replicating these steps.
Copy code
{
    record = require('N/record');

    itemSublist = 'inventory';
    
    newrec = record.create({
        type: 'inventorytransfer',
        dynamic: true,
        defaultValues: {}
    });

    newrec.setValue({fieldId:'subsidiary', value: 1 });
    newrec.setValue({fieldId:'transferlocation', value: 19 });
    newrec.setValue({fieldId:'location', value: 25 });

    newrec.insertLine({sublistId: itemSublist, line: 0}); 

    newrec.setSublistValue({sublistId: itemSublist, fieldId:'itemreceive', line: 0, value:true});
    newrec.setSublistValue({sublistId: itemSublist, fieldId:'quantity', line: 0, value:10});
    
    newrec.getSublistSubrecord({sublistId: itemSublist, fieldId: 'inventorydetail', line:0});
    console.log(newrec.hasSublistSubrecord({sublistId: itemSublist, fieldId:'inventorydetail', line:0}))
}
I've tried selectLine and setCurrentSublistValue as well with similar results.
n
Have you tried it with newrec.selectNewLine() instead of .insertline? And then use setCurrentSublistValue() Something like this
Copy code
{
	record = require('N/record');

	itemSublist = 'inventory';

	newrec = record.create({
		type: 'inventorytransfer',
		dynamic: true,
		defaultValues: {}
	});

	newrec.setValue({fieldId: 'subsidiary', value: 1});
	newrec.setValue({fieldId: 'transferlocation', value: 19});
	newrec.setValue({fieldId: 'location', value: 25});

	newrec.selectNewLine({sublistId: itemSublist});

	newrec.setCurrentSublistValue({sublistId: itemSublist, fieldId: 'itemreceive', value: true});
	newrec.setCurrentSublistValue({sublistId: itemSublist, fieldId: 'quantity', value: 10});

	newrec.getCurrentSublistSubrecord({sublistId: itemSublist, fieldId: 'inventorydetail'});
	console.log(newrec.hasSublistSubrecord({sublistId: itemSublist, fieldId: 'inventorydetail', line: 0}))
}
r
Giving it a try on the server, in the browser "selectNewLine" is not a function.
That worked. Funky the behavior differences even though both are client side
now issues with the getCurrentSublistSubrecord for the inventorydetail.
n
What error is it giving you? If you manually create an inventory transfer in the UI and add that item to the line does it let you configure the inventory detail? It may be an item configuration issue if the item youre using doesnt use inventory detail
r
Figured it out, I was missing the obvious bit about the actual "itemid" trying to get transferred. Second part after that, was using the correct "adjquantity"
Something with the UI gives slightly different behavior, even though the script is executing in the UI.
But it's working now, thanks for the selectNewLine suggestion.
n
👍