this code sample takes the values of the form from postman in the form of Json content
/**
* @NApiVersion 2.1
* @NScriptType Suitelet
*/
define([‘N/currentRecord’, ‘N/record’, ‘N/ui/serverWidget’],
/**
* @param{currentRecord} currentRecord
* @param{record} record
* @param{serverWidget} serverWidget
*/
(currentRecord, record, serverWidget) => {
/**
* Defines the Suitelet script trigger point.
* @param {Object} scriptContext
* @param {ServerRequest} scriptContext.request – Incoming request
* @param {ServerResponse} scriptContext.response – Suitelet response
* @since 2015.2
*/
const onRequest = (scriptContext) => {
if(scriptContext.request.method === “GET”){
var form = serverWidget.createForm({
title : “Patient Details Form”
});
var container = form.addFieldGroup({
id : ‘patientInfo’,
label : ‘Patient Details’
});
form.addField({
id : ‘custpage_name’,
type: serverWidget.FieldType.TEXT,
label : ‘Name’,
container : ‘patientInfo’
});
form.addField({
id : ‘custpage_age’,
type: serverWidget.FieldType.INTEGER,
label : ‘Age’,
container : ‘patientInfo’
});
form.addField({
id : ‘custpage_address’,
type: serverWidget.FieldType.TEXT,
label : ‘Address’,
container : ‘patientInfo’
});
form.addField({
id : ‘custpage_sex’,
type: serverWidget.FieldType.TEXT,
label : ‘Sex’,
// source : ‘423’,
container : ‘patientInfo’
});
form.addSubmitButton({
label : ‘Submit’
});
scriptContext.response.writePage(form);
} else if(scriptContext.request.method === ‘POST’){
var data = JSON.parse(scriptContext.request.body);
log.debug(‘data’,data)
let name = data.custpage_name;
let age = data.custpage_age;
let addr = data.custpage_address;
let sex = data.custpage_sex;
log.debug(‘name’,name)
log.debug(“test”)
var details = ‘<h2>PATIENT FORM </h2>’;
details += ‘<p><b> Name:</b> ‘ + name + ‘<p>’;
details += ‘<p><b> age:</b> ‘ + age + ‘<p>’;
details += ‘<p><b> address:</b> ‘ + addr + ‘<p>’;
details += ‘<p><b> sex:</b> ‘ + sex + ‘<p>’;
scriptContext.response.write(details);
var customerecord = record.create({
type : ‘customrecord_jj_patient’,
isDynamic : true
});
customerecord.setValue({
fieldId : ‘custrecord1’,
value : name
});
customerecord.setValue({
fieldId : ‘custrecord2’,
value : age
});
customerecord.setValue({
fieldId : ‘custrecord3’,
value : sex
});
customerecord.setValue({
fieldId : ‘custrecord4’,
value : addr
});
var recordId = customerecord.save({ ignoreMandatoryFields: false, enableSourcing: true });
log.debug(“customer recordId:”, + recordId);
return recordId;
}
}
return {onRequest}
});