I am trying to present two tips in this single tip as both needs the same concept.
1.How to show alert message for a suitelet page after clicking an Submit button
2.How to show an alert message if a suitelet page with sublist containing checkbox as one of the field in sublist
The below content will solve the two problems
Situation:
A suitelet page with sublist which includes checkbox column along with some other columns.
Figure below shows an suitelet page, where the sublist contains checkbox column along with other columns.
Now we need to show alert if none of the checkbox has been checked and user clicked the “Print” button which is a submit button.
Possible Solutions:
1.As we know we can’t attach any function to the submit button, so that possible solution is gone.
2.We can add “setMandatory(true)” to that checkbox field like:
sublist.addfield(“select”,”checkbox”,”Select” ).setMandatory(true);
but that will not work.
Means if you will write code in suitelet script
sublist.addfield(“select”,”radio”,”Select” ).setMandatory(true);
and if will click the “Print” button without selecting the radio button in the sublist, then it will show an alert automatically.
But that will not work for “Checkbox” field.
Solution:
Here is the solution if you are facing such problem.
Steps:
1.Create Suitelet script(customscript_suitelet_script) with all required fields and buttons.
function CreateForm(request, response){ if(request.getMethod() == "GET"){ //Create form var form = nlapiCreateForm("Sample Form", true); //Add Submit Button and Tab form.addSubmitButton("Print"); form.addTab("custpage_list", "Lot Number List"); //Add sublist to form var sublist = argForm.addSubList("custpage_sublist", "list", "Lot Numbers", "custpage_list"); sublist.addField("custpage_select", "checkbox", "Select"); sublist.addField("custpage_itemnumber", "select", "Item", "item"); …...... //Add other fields to sublist and form response.writePage(form); } else{ //Do whatever you want to do after Print button click } }
2.Create a client script file(customscript_client_script), and add the following code there :
function SaveRecord(){ var isChecked = "F"; //Get Line Item Count var lineCount = nlapiGetLineItemCount("custpage_sublist"); if (lineCount > 0) { for (var line = 1; line