ashbaq1
ashbaq1

Reputation: 45

Adding Button in standard form in netsuite

Hi i am trying to add a button in a standard form by using a user event triggered function but it didn't alert me.

function clickMe() {
    alert('Button was clicked from "+nlapiGetRecordType()+" in VIEW mode');
}

function myBeforeLoad(type, form, request) {
    var customButton=form.addButton('custpage_mybutton','MyFirstButton','clickMe();');
}` 

Upvotes: 1

Views: 4593

Answers (5)

alanmarklewis
alanmarklewis

Reputation: 31

The script needs to be applied to the form before you create the button and set the function you want to call from the ClientScript.

if (type == 'view')
    {
       form.setScript('customscript_asw_ss_cs_member');
       form.addButton('custpage_mybutton','MEMBERSCRIPT','onclick_callAlert()');
    }

Upvotes: 2

ashbaq1
ashbaq1

Reputation: 45

This is user event script function myBeforeLoad(type, form) { if (type=='view'){
var customButton = form.addButton('custpage_mybutton','MEMBER SCRIPT','onclick_callAlert()'); form.setScript('customscript_asw_ss_cs_member'); } }

This is Client Script

function onclick_callAlert() { alert('hi'); }

Thanks For You All Replies....

Upvotes: 1

michoel
michoel

Reputation: 3783

While generally the better way to do this is with a separate client script like the other answers, for a simple one-liner you can get away with hard coding the script into a string, e.g.

function myBeforeLoad(type, form, request) {
    var script = "alert(\'Button was clicked from \' + nlapiGetRecordType() + \' in VIEW mode\');";
    var customButton = form.addButton('custpage_mybutton','MyFirstButton',script);
}

Upvotes: 1

Rusty Shackles
Rusty Shackles

Reputation: 2840

You need to attach your script to the form. You can do this by using form.setScript(nlapiGetExecutionContext().getScriptId());

Upvotes: 2

erictgrubaugh
erictgrubaugh

Reputation: 8847

Is your clickMe function defined in your User Event or your Client script? In order to be executed from a button click, the function must exist on the client side, so you need to define it in a client script.

Upvotes: 2

Related Questions