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

I have a question: how can i Access Customer Fields  from Sales Order Suitelet. I need to get a value from customer record and update it after sales order is successful.

Rookie Answered on February 13, 2020.
try {
var sales_order_id = salesOrder.save({

ignoreMandatoryFields: true

});
log.debug(‘record save with id’, sales_order_id);//sales order internal id
// load customer record
var customer = record.load({
type: record.Type.CUSTOMER,
id: salesOrder.getValue('entity'),
isDynamic: false
});
customer.setValue({ fieldId: 'myfield', value: 'my new value'});
var customerId = customer.save();
return id;
} catch (e) {

return 0;
}

The above modification to the existing example code will load the customer record from the Sales order after you’ve saved the sales order.  As a side note: I would recommend that likely a more “appropriate” place for the code where you want to change a value on the customer record after saving the sales order would be to use the afterSubmit function of a UserEvent script on the SalesOrder record type itself.

Also, if you already know the value and field(s) that you want to set on the customer record, it’s going to be more efficient to use record.submitFields function rather than loading the customer record/setting values/saving customer record as I show above.

using record.submitFields, replace the above code with the below code:

record.submitFields({
type: record.Type.CUSTOMER,
id: salesOrder.getValue('entity'),
values: { my_field_id1: my_new_value1, my_field2: my_new_value2 },
options: {
        enableSourcing: false,
        ignoreMandatoryFields: true
    }
});

 

Sorry I was late to the party but I hope you find this useful.

on February 20, 2021.
Add Comment

Your Answer

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