RE: Post json response to suitelet to create sales order in Netsuite. We are using version 2 *@NApiVersion 2.x

I need to write a suitelet to get data submitted from html page as json response and use this data to create a sales order page

This is sample response from html submit button

GET – https://www.xyz.com/example.html/?callback=jQuery545221&{%22orderdetail%22:[{%22id%22:%2289%22,%22quantity%22:2,%22price%22:%2213.96%22,%22amount%22:%2227.92%22},
{%22id%22:%2280%22,%22quantity%22:1,%22price%22:%2212.95%22,%22amount%22:%2212.95%22},
{%22id%22:%2281%22,%22quantity%22:2,%22price%22:%2210.95%22,%22amount%22:%2221.90%22},
{%22id%22:%2283%22,%22quantity%22:3,%22price%22:%2212.56%22,%22amount%22:%2237.68%22},
{%22id%22:%2275%22,%22quantity%22:4,%22price%22:%2212.95%22,%22amount%22:%2251.80%22}],
%22customer_id%22:%22180%20xyz%20abc%22,%22total_amount%22:%22152.25%22}&_=1580411441286

where id = 89 , quantity = 2, price = 13.96, amount = 27.92 (2*13.96) in first line
id = 80 , quantity = 1, price = 12.95, amount = 12.95 (1*12.95) in second line and so on’
here are total 5 different items in same order (in array orders)
and in last line
there is customer_id =180 xyz abc , total amount = 152.25

I need help in processing this response to suitelet to create a sales order.

sadi Rookie Asked on February 4, 2020 in SuiteScript.

just serialize it manually

on April 7, 2021.
Add Comment
12 Answers

Thank u for reply. I have tried this code, can u please help me where to put your code, this is my very first time writing suitelet

 

/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define([‘N/search’, ‘N/record’],
function (search, record) {
function onRequest(context) {
if (context.request.method === ‘GET’) {

// Get parameters
var customer_id = context.request.parameters.customer_id;
var total_amount = context.request.parameters.total_amount;
var id = context.request.parameters.id;
var quantity = context.request.parameters.quantity;
var price = context.request.parameters.price;
var amount = context.request.parameters.amount;

var salesOrder = record.create({
type: record.Type.SALES_ORDER,
isDynamic: true,
});

// memo
salesOrder.setValue({
fieldId: ‘memo’,
value: Testing
});

// Set customform
salesOrder.setValue({
fieldId: ‘customform’,
value: ‘123’ //internal id
});

// Set shipmethod
salesOrder.setValue({
fieldId: ‘shipmethod’,
value: ‘123’ //internal id
});

// Shipping Carrier
salesOrder.setValue({
fieldId: ‘shipcarrier’,
value: FedEx
});

//Sales representative
salesOrder.setValue({
fieldId: ‘salesrep’,
value: ‘123’ //internal id
});

salesOrder.selectNewLine({
sublistId: ‘item’
});

salesOrder.setCurrentSublistValue({
sublistId: ‘item’,
fieldId: ‘item’,
value: item.id
});

salesOrder.setCurrentSublistValue({
sublistId: ‘item’,
fieldId: ‘tax’,
value: 0
});

salesOrder.setCurrentSublistValue({
sublistId: ‘item’,
fieldId: ‘quantity’,
value: item.quantity
});

salesOrder.setCurrentSublistValue({
sublistId: ‘item’,
fieldId: ‘rate’,
value: item.price
});

salesOrder.setCurrentSublistValue({
sublistId: ‘item’,
fieldId: ‘amount’,
value: item.amount
});

salesOrder.commitLine({
sublistId: ‘item’
});

try {

var sales_order_id = salesOrder.save({
ignoreMandatoryFields: true
});

log.debug(‘record save with id’, sales_order_id);//sales order internal id
return id;

} catch (e) {
return 0;

}

return {
onRequest: onRequest
};
});

Rookie Answered on February 4, 2020.
Add Comment

Your Answer

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