RE: Store form fields’ data in JavaScript Object

Hello, I have a form in Suitelet which contains various text fields, select, radio buttons etc., Once the data is entered in the available fields, on submitting the form, all the data entered must be stored in a JavaScript object (for eg: in “Age” field, if the value entered in “22”, in “Gender” field, value entered is “male”. The Javascript object should be {age: 22, gender: male}). But in the suitelet form, the fields are dynamically generated, so I cannot specifically use request.parameters.age pr request.parameters.gender. How to create and store data in Javascript object in the above said format for a dynamically generated suitelet form and send it to a particular record.

Thanks

rams Rookie Asked on September 12, 2019 in SuiteScript.

You probably need to give more details about how your form is generated and its relation to the keys you need to set on your javascript object.

on September 12, 2019.
Add Comment
3 Answers

I have done this in the past.

In the Suitelet while creating the form add

a code behind page… This will be a NetSuite client script behind your Suitelet.

form.clientScriptModulePath = './clientscriptname.js';

 

In the Client scripts Save Event

you and grad the values entered into your fields on the suitelet like this

 

var rec = scriptContext.currentRecord;
var newphone = rec.getValue('phone');

Or better create an object

 

function saveRecord(scriptContext) {
var rec = scriptContext.currentRecord;
var newcontact = {}
newcontact.name = rec.getValue('custpage_name');
newcontact.age = rec.getValue('custpage_age');
newcontact.age = rec.getValue('custpage_gender');
newcontact.phone = rec.getValue('custpage_phone');
 ...do stuff with the object...
return true;
}

 

Then do whatever you like with the JS Object newcontact,  Create or update a record,  Pass the object as paramenter to somewhere else etc…

 

Hope this helps

Sean

 

Rookie Answered on September 12, 2019.
Add Comment

Your Answer

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