Hi All, I'm trying to create Purchase order from S...
# suitescript
j
Hi All, I'm trying to create Purchase order from Sales Quotation (Estimate) . Trying to set the line item, while committing the line im getting error: Line validation failed for sublist: item Any assitance?
b
what does the code look like
j
define(['N/record', 'N/error', 'N/ui/message', 'N/ui/dialog', 'N/url','N/runtime'], function(record, error, message, dialog, url,runtime) { function pageInit() { } function createPurchaseOrder(estimateId) { if (!estimateId) { alert('Estimate Id Missing'); return; }else{ //window.location.reload() try { var quotationRecObj = record.load({ type: 'estimate', id: estimateId }); var customer = quotationRecObj.getValue('entity'); var subsidiary = quotationRecObj.getValue('subsidiary'); var rq_id = quotationRecObj.getValue('recordid'); var otherrefnum = quotationRecObj.getValue('otherrefnum'); var custbody_incoterms = quotationRecObj.getValue('custbody_incoterms'); var custbody_oem = quotationRecObj.getValue('custbody_oem'); var custbody_pocurrency = quotationRecObj.getValue('custbody_pocurrency'); var memo = quotationRecObj.getValue('memo'); var data = { 'customer' : customer, 'rq_id' : rq_id, 'subsidiary': subsidiary, 'ref number' : otherrefnum, 'incoterms' : custbody_incoterms, 'oem': custbody_oem, 'pocurrency' : custbody_pocurrency, 'memo' : memo } log.debug('data',data) var purchaseOrderRecord = record.create({ type: record.Type.PURCHASE_ORDER, isDynamic: true }); // Set field values on the Purchase Order record purchaseOrderRecord.setValue({ fieldId: 'customform', value: 100 }); purchaseOrderRecord.setValue('entity', custbody_oem); purchaseOrderRecord.setValue('memo', memo); purchaseOrderRecord.setValue('otherrefnum', otherrefnum); purchaseOrderRecord.setValue('custbody_potype', "1");//set po type purchaseOrderRecord.setValue('subsidiary', subsidiary); purchaseOrderRecord.setValue('custbody_incoterms', custbody_incoterms); purchaseOrderRecord.setValue('currency', custbody_pocurrency); //purchaseOrderRecord.setValue('location', "7"); purchaseOrderRecord.setValue('custbody_nn_est_no', estimateId); // Add line items to the Purchase Order record var lineCount = quotationRecObj.getLineCount('item'); log.debug("lineCount",lineCount) if (lineCount > 0) { for (var i = 0; i <lineCount; i++) { // Retrieve values from the requisition record's sublist var item = quotationRecObj.getSublistText('item', 'item', i); var description = quotationRecObj.getSublistValue('item', 'description', i); var qty = quotationRecObj.getSublistValue('item', 'quantity', i); var units = quotationRecObj.getSublistValue('item', 'units', i); var rate = quotationRecObj.getSublistValue('item', 'rate', i); var tax_code = quotationRecObj.getSublistValue('item', 'taxcode', i); var amount = quotationRecObj.getSublistValue('item', 'amount', i); var tax_rate = quotationRecObj.getSublistValue('item', 'taxrate1', i); var gross_amount = quotationRecObj.getSublistValue('item', 'grossamt', i); var tax_amount = quotationRecObj.getSublistValue('item', 'tax1amt', i); var division = quotationRecObj.getSublistValue('item', 'department', i); var eom = quotationRecObj.getSublistValue('item', 'class', i); item_data = { "item" : item, "quantity" : qty , "taxCode" : tax_code } log.debug('Item Detail',item_data) purchaseOrderRecord.insertLine({ sublistId: 'item', line: i }); purchaseOrderRecord.setCurrentSublistText({ sublistId: 'item', fieldId: 'item', text: item, line: i }); purchaseOrderRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'quantity', value: qty, line: i }); purchaseOrderRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'isclosed', value: true, // Set isclosed field to true line: i }); // purchaseOrderRecord.setCurrentSublistValue({ // sublistId: 'item', // fieldId: 'units', // line: i, // value: units, // }); // purchaseOrderRecord.setCurrentSublistValue({ // sublistId: 'item', // fieldId: 'rate', // line: i, // value: parseFloat(rate), // }); // purchaseOrderRecord.setCurrentSublistValue({ // sublistId: 'item', // fieldId: 'taxcode', // line: i, // value: tax_code, // }); // purchaseOrderRecord.setCurrentSublistValue({ // sublistId: 'item', // fieldId: 'taxrate1', // line: i, // value: tax_rate, // }); // purchaseOrderRecord.setCurrentSublistValue({ // sublistId: 'item', // fieldId: 'amount', // line: i, // value: amount, // }); // purchaseOrderRecord.setCurrentSublistValue({ // sublistId: 'item', // fieldId: 'grossamt', // line: i, // value: gross_amount, // }); // purchaseOrderRecord.setCurrentSublistValue({ // sublistId: 'item', // fieldId: 'department', // line: i, // value: division, // }); // purchaseOrderRecord.setCurrentSublistValue({ // sublistId: 'item', // fieldId: 'class', // line: i, // value: eom, // }); // purchaseOrderRecord.setCurrentSublistValue({ // sublistId: 'item', // fieldId: 'tax1amt', // line: i, // value: tax_amount, // }); purchaseOrderRecord.commitLine({ sublistId: 'item' }); } } // Save the Purchase Order record var purchaseOrderId = purchaseOrderRecord.save({ enableSourcing: true, ignoreMandatoryFields: false }); // Redirect to the newly created Purchase Order var purchaseOrderURL = url.resolveRecord({ recordType: record.Type.PURCHASE_ORDER, recordId: purchaseOrderId, isEditMode: true }); window.location.href = purchaseOrderURL; return true; } catch (e) { console.log(e); alert('Error creating Purchase Order: ' + e); return false; } } } return { pageInit: pageInit, createPurchseOrder: createPurchaseOrder }; });
b
the error from a dynamic mode record should tell you which line is causing the problem
j
this is the error im getting Error creating Purchase Order: {"type":"error.SuiteScriptError","name":"USER_ERROR","message":"Line validation failed for sublist: item","id":null,"stack":["USER_ERROR: Line validation failed for sublist: item"," at Object.createError [as nlapiCreateError] (https://7929734-sb1.app.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2023.1&amp;minver=15&amp;buildver=30763:828:16)"," at Object.createError [as create] (https://7929734-sb1.app.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2023.1&amp;minver=15&amp;buildver=30763:2109:42)"," at _assertValidation (https://7929734-sb1.app.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2023.1&amp;minver=15&amp;buildver=30763:65150:118)"," at https://7929734-sb1.app.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2023.1&amp;minver=15&amp;buildver=30763:65040:6"," at Result.then (https://7929734-sb1.app.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2023.1&amp;minver=15&amp;buildver=30763:2471:21)"," at Function.runAndAssertInternalScript (https://7929734-sb1.app.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2023.1&amp;minver=15&amp;buildver=30763:65038:8)"," at thenableFunction(runAndAssertInternalScript).thenable (https://7929734-sb1.app.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2023.1&amp;minver=15&amp;buildver=30763:3791:26)"," at Function.runMergeAndAssertInternalScript (https://7929734-sb1.app.netsuite.com/javascript/suitescript/2.0/client/N.js?NS_VER=2023.1&amp;minver=15&amp;buildver=30763:65025:39)"," at ...
b
keep on exploring the stack at the
...