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
Also note that even dynamically generate fields have an id. You may need to look at the Suitelet to see what it is, but it should have one. For example,
var form = nlapiCreateForm("Serial Number Search"); form.addField('custpage_snsearch_insn', 'text', 'Serial Number'); form.addSubmitButton('Search'); response.writePage(form);
You’ll notice that the field has an id ‘custpage_snsearch_insn‘. Even fields that are added conditionally will have this, and you can use that with request.parameters to get the data.
If the text fields, select, and radio buttons aren’t created using the form API (for example, if your using something like Vue for data entry), you’ll need to attach a client script which finds the fields (using document.getElementById()), converts them to a JS object, and saves them to a hidden field created using the form method shown above. You can attach this code to the saveRecord() event and I think that should do it.
Also, it’s much easier to help if you post some code :). If you can, that’d be fantastic.
battk
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.