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.


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

What if you add a prefix to all of the dynamic fields? So use ‘myprefix_age’ and ‘myprefix_gender’ instead. Then in the Suitelet, retrieve them with something like this:

var obj = {};
for (var key in context.request.parameters) {
    if (key.indexOf('myprefix_') === 0) {
          obj[key.replace('myprefix_', '')] = context.request.parameters[key];
Beginner Answered on September 12, 2019.
Add Comment

Your Answer

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