Я не могу сохранить счет поставщика, поскольку возникнет ошибка, из-за которой требуются данные инвентаризации, если я их не введу. Однако, когда я пытаюсь ввести какие-либо значения для полей, связанных с инвентаризацией, появляется сообщение об ошибке «Невозможно создать детали инвентаризации для этого элемента». Доступны следующие поля элемента (скопированы из отладчика):
amount = {string}
amounthasbeenset = {string}
billreceipts = {string}
billvariancestatus = {string}
billvariancestatusallbook = {string}
binitem = {string}
class = {string}
customer = {string}
ddistrib = {string}
department = {string}
description = {string}
fulfillable = {string}
fulfillmentstatus = {string}
generateaccruals = {string}
groupsetup = {string}
hasimmutableamortization = {string}
id = {string}
inboundshipmentitem = {string}
includegroupwrapper = {string}
ingroup = {string}
initoqpbucket = {string}
initquantity = {string}
inventorydetailavail = {string}
inventorydetailreq = {string}
isbillable = {string}
islinefulfilled = {string}
islinkedtodropshippoline = {string}
isnoninventory = {string}
isnumbered = {string}
isserial = {string}
item = {string}
itemhandlingcost = {string}
itemresidamt = {string}
itemresidamtispct = {string}
itemshippingcost = {string}
itemsubtype = {string}
itemtype = {string}
landedcostcategory = {string}
landedcostset = {string}
linenumber = {string}
location = {string}
locationusebins = {string}
locationusesbins = {string}
mandatorylocation = {string}
marginal = {string}
matrixtype = {string}
olditemid = {string}
options = {string}
oqpbucket = {string}
orderdoc = {string}
orderline = {string}
origlocation = {string}
origrate = {string}
printitems = {string}
quantity = {string}
rate = {string}
rateschedule = {string}
scheduletype = {string}
tracklandedcost = {string}
vendorname = {string}
weightinlb = {string}
Я устанавливаю следующие значения данных инвентаризации (в дополнение к номеру, количеству и местоположению). Подсписок присвоения инвентаря отсутствует.
inventorydetailavail = F
inventorydetailreq = F
binitem = F
isserial = F
isnumbered = F
locationusesbins = F
locationusebins = F
itemtype = NonInvtPart
isnoninventory = T
Вот пример кода, который я использую:
define(['N/record','N/redirect','N/search'],
function(record, redirect, search) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
function onRequest(context) {
var request = context.request;
var response = context.response;
var id = context.request.parameters.custom_id;
if (!id) {
context.response.write('The parameter "custom_id" is required');
return;
}
else {
alert('ID is ' + id);
}
var loadedRecord = record.load({
type: record.Type.INBOUND_SHIPMENT,
id: id
});
alert('Generating vendor bill');
var shipmentBaseCurrency = loadedRecord.getValue('shipmentbasecurrency');
var vendorBill = record.create({
type: record.Type.VENDOR_BILL,
isDynamic: true
});
vendorBill.setValue('currency', shipmentBaseCurrency);
var receivingLocation = '';
var lines = loadedRecord.getLineCount({sublistId: 'items'});
log.debug("tran. lines: " + lines);
var total;
for (var i = 0; i < lines; i++) {
var quantity = (parseFloat(loadedRecord.getSublistValue({
sublistId: "items",
fieldId: "quantityreceived",
line: i
})) || 0);
var purchaseOrder = loadedRecord.getSublistValue({
sublistId: "items",
fieldId: "purchaseorder",
line: i
});
var item = loadedRecord.getSublistValue({
sublistId: "items",
fieldId: "itemid",
line: i
});
var description = loadedRecord.getSublistValue({
sublistId: "items",
fieldId: "shipmentitemdescription",
line: i
});
var recLoc = loadedRecord.getSublistValue({
sublistId: "items",
fieldId: "receivinglocation",
line: i
});
receivingLocation = recLoc;
var totalUnitCost = loadedRecord.getSublistValue({
sublistId: "items",
fieldId: "totalunitcost",
line: i
});
var amount = loadedRecord.getSublistValue({
sublistId: "items",
fieldId: "shipmentitemamount",
line: i
});
log.debug("item quantity: " + quantity);
vendorBill = addVendorBillLine(vendorBill, item, quantity, receivingLocation);
} // for (var i = 0; i < lines; i++)
var vbPostPeriodValStr = String(getPostingPeriod());
try {
vendorBill.setText('postingperiod', vbPostPeriodValStr);
}
catch(e) {
log.error('Issue setting posting period for vendor bill', e.message);
}
vendorBill.setValue('location', receivingLocation);
try {
var vendorBillId = vendorBill.save();
log.debug('*******Vendor Bill Saved*******', 'Vendor bill successfully saved: ' + vendorBillId);
redirect.toRecord({
type: record.Type.VENDOR_BILL,
id: vendorBillId
});
}
catch(e) {
log.debug('Error saving vendor bill', e.message);
context.response.write('Error: ' + e.message);
}
}
function addVendorBillLine(vendorBill, item, quantity, location) {
try {
var lineNum = vendorBill.selectNewLine({
sublistId: 'item'
});
vendorBill.setCurrentSublistValue({
sublistId: "item",
fieldId: "item",
value: item
});
vendorBill.setCurrentSublistValue({
sublistId: "item",
fieldId: "quantity",
value: quantity
});
vendorBill.setCurrentSublistValue({
sublistId: "item",
fieldId: "location",
value: location
});
vendorBill.setCurrentSublistValue({
sublistId: "item",
fieldId: "itemtype",
value: 'NonInvtPart'
});
vendorBill.setCurrentSublistValue({
sublistId: "item",
fieldId: "isnoninventory",
value: 'T'
});
vendorBill.setCurrentSublistValue({
sublistId: "item",
fieldId: "inventorydetailreq",
value: 'F'
});
vendorBill.setCurrentSublistValue({
sublistId: "item",
fieldId: "inventorydetailavail",
value: 'F'
});
vendorBill.setCurrentSublistValue({
sublistId: "item",
fieldId: "binitem",
value: 'F'
});
vendorBill.setCurrentSublistValue({
sublistId: "item",
fieldId: "locationusebins",
value: 'F'
});
vendorBill.setCurrentSublistValue({
sublistId: "item",
fieldId: "vendorname",
value: 'Test Vendor'
});
vendorBill.commitLine({sublistId:"item"});
log.debug('Committing vendor bill expense line addition','Name: ' + item + ", Quantity: " + quantity);
}
catch(e){
log.debug('Issue committing vendor bill item line addition', e.message);
}
return vendorBill;
}
function getPostingPeriod() {
var monthAbbr = [
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
];
var d = new Date();
return monthAbbr[d.getMonth()] + ' ' + d.getFullYear();
}
return {
onRequest: onRequest
};
});