admin管理员组

文章数量:1323728

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();');
}` 

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();');
}` 
Share Improve this question edited Jul 16, 2016 at 10:38 HiDeoo 10.6k8 gold badges51 silver badges49 bronze badges asked Jul 16, 2016 at 9:30 ashbaq1ashbaq1 451 silver badge8 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 2

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.

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

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()');
    }

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);
}

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....

本文标签: javascriptAdding Button in standard form in netsuiteStack Overflow