Warm tip: This article is reproduced from stackoverflow.com, please click
function javascript button netsuite suitescript

How can I raise the alarm after unsuccessful text validation after clicking (addSubmitButton) "Send"

发布于 2020-03-27 10:22:09

I am new to SuiteScript and I am looking for some help with this problem. I need to do a simple validation that will throw an alert() when the company's vat number entered in the text box is incorrect (without "-", space, and a specified length).

This is for SuiteScript 1.0 API.

function findCompanyVATNumber(request, response){

    //Here is a non-valid code

    if(request.getMethod() === 'GET')
    {
        var form = nlapiCreateForm('Look for companies in the system', false);
        var vatNumber = form.addField('custpage_taxnumber', 'text', 'Comanies vat number:', null, null);
        vatNumber.setDefaultValue('');

        form.addSubmitButton('search');

        response.writePage(form);

    }else{
        //Here is a non-valid code
    }
}

I expect that alert box will appear with information whats wrong with number if the entered value does not match the given function, and if the entered vat number is correct, the addSubmitButton will work like usual and will go to the page displaying information about the company.

Questioner
Tenecious
Viewed
74
erictgrubaugh 2019-07-04 01:31

You'll need to attach a Client Script to your Form object, and that Client Script will need to implement a handler for the saveRecord event. There is a method on nlobjForm for attaching a Client Script; see the Help documentation for the object for more details.

FWIW I advise you write any new code in SuiteScript 2.0, rather than 1.0.