RE: How to create or update multiple records using Json request ?

Hi,

I am new in SuiteScript and getting error ‘org.mozilla.javascript.Undefined@7dee967’

when I am trying to create or update multiple record using Json request. But it is working fine when sending request for a single record.

Below is my restlet:

function search_data(datain)
{
var current_Subsidiary = nlapiGetSubsidiary();
if (current_Subsidiary == 1)
{
if (datain.recordtype == ‘aggregatorsale’)
{
if (datain.operation == ‘create’) {
nlapiLogExecution(‘DEBUG’, ‘aggregatorsale create req’, JSON.stringify(datain));
var o_search_result = create_aggregatorsale(datain);
nlapiLogExecution(‘DEBUG’, ‘create_aggregatorsale’, datain.recordtype + ‘ o_search_result=====’ + JSON.stringify(o_search_result));
return o_search_result;
}

}

}
}

 

function create_aggregatorsale(datain) {
nlapiLogExecution(‘DEBUG’, ‘create_aggregatorsale’, JSON.stringify(datain));

var rec = nlapiCreateRecord(“customrecord_aggregator_sale”);
rec.setFieldValue(‘custrecord_as_state’, datain.state);
rec.setFieldValue(‘custrecord_as_region’, datain.region);
rec.setFieldValue(‘custrecord_as_batch_date’, datain.batch_date);
rec.setFieldValue(‘custrecord_as_branchid’, datain.brachid);
rec.setFieldValue(‘custrecord_as_branch_name’, datain.branch_name);
rec.setFieldValue(‘custrecord_as_loanid’, datain.loanid);

var recId = nlapiSubmitRecord(rec);
var o_succss_obj = new Object();

if (recId > 0) {
o_succss_obj.Message = “Created Sucessfully”;
o_succss_obj.recordid = recId;

} else {
o_succss_obj.Message = “Failed”;
o_succss_obj.recordid = null;
}

return o_succss_obj;

}

And below is my Json request:

[
{
“operation”: “create”,
“recordtype”: “aggregatorsale”,
“state”: “Maharashtra”,
“region”: “Beed”,
“batch_date”: “09/09/2020”,
“brachid”: “25:04”,
“branch_name”: “Sonpeth”,
“loanid”: “5114509000011053”
},
{
“operation”: “create”,
“recordtype”: “aggregatorsale”,
“state”: “Maharashtra”,
“region”: “Beed”,
“batch_date”: “09/09/2020”,
“brachid”: “25:04”,
“branch_name”: “Sonpeth”,
“loanid”: “5114509000011054”
}
]

Please help me to resolve this.

Thank you!

Titu Rookie Asked on March 11, 2021 in SuiteScript.
Add Comment
1 Answers

Learn how to work with Arrays. You should have some sort of looping mechanism to process each element of your data array.

Intermediate Answered on March 11, 2021.

Where and how I have to write? Can you please do it?

 

on March 11, 2021.
Add Comment

Your Answer

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