Netsuite suitescript在单击按钮时运行函数

Netsuite suitescript在单击按钮时运行函数,netsuite,suitescript,Netsuite,Suitescript,重演: 我希望在单击按钮时运行脚本(因为您无法在单击按钮时运行脚本中的函数)。我遵循了Suitescript文档,只能运行第二个日志。有什么想法吗 ` form.setScript('customscript_toloader') form.addButton('custpagetestbutton', 'TEST button', 'createTO();');` -其他脚本 function createTO() //(request, response) { alert("Thi

重演: 我希望在单击按钮时运行脚本(因为您无法在单击按钮时运行脚本中的函数)。我遵循了Suitescript文档,只能运行第二个日志。有什么想法吗

` form.setScript('customscript_toloader')
 form.addButton('custpagetestbutton', 'TEST button', 'createTO();');`
-其他脚本

function createTO() //(request, response)
{   
alert("This function was called");
//variable set up
    nlapiLogExecution('DEBUG', 'script', 'runs 1');
    var POID ;
    var POType ;
    var PORecord;
    var lines;
  nlapiLogExecution('DEBUG', 'script', 'runs 2');
    var arrayName = new Array();
    var arrayQty = new Array();
    PORecord = nlapiGetNewRecord();
    lines = PORecord.getLineItemCount('item');
    POID = nlapiGetRecordId();
    POTYPE = nlapiGetRecordType();
    // get name and quantity
    for ( var i = 1; i < lines + 1 ; i++ )
    {
        arrayName[i] = PORecord.getLineItemValue('item', 'item', i ); 
        arrayQty[i] = PORecord.getLineItemValue('item', 'quantity' , i);
    }
    nlapiLogExecution('DEBUG', 'script', 'runs 3');

    //creates to and changes focus
    var TOrecord = nlapiCreateRecord ('transferorder');
    var TOrecordID = TOrecord.getId();
    TOrecord.setFieldValue('customform',128);
    //subsidiaries CC bedford id is 2
    TOrecord.setFieldValue('subsidiary',2);
    //testing for location and transfer location, 144 & 145
    TOrecord.setFieldValue('location',144);
    TOrecord.setFieldValue('transferlocation',145);
    TOrecord.setFieldValue('memo', 'PO: ' + POID );
    TOrecord.setFieldValue('employee',nlapiGetContext().getUser());
    //TOrecord.setFieldValue('department',"C-C");

    //set name and quantity
    for ( var j = 1; j < lines +1  ; j++ )
    {
        arrayName[j] = parseInt(arrayName[j]); 
        TOrecord.setLineItemValue("item", "item", j , arrayName[j] );
        TOrecord.setLineItemValue("item", "quantity", j , parseInt(arrayQty[j])); //added parse int, should work

    }


    // set the item and location values on the currently selected line
    nlapiSetCurrentLineItemValue('item', 'location', 6);
    // commit the line to the database
    //nlapiCommitLineItem('item');

    var TOResult = nlapiSubmitRecord(TOrecord, true, true);
    var TOTranID= nlapiLookupField('transferorder', TOResult, 'tranid');
    var poURL = nlapiResolveURL('RECORD', 'transferorder', TOResult);

    nlapiSetRedirectURL('RECORD','transferorder', TOResult);
    return;
     }
函数createTO()/(请求、响应)
{   
警报(“调用了此函数”);
//变量设置
nlapiLogExecution('DEBUG','script','runs1');
波伊德变量;
变异型;
变异孔索;
var线;
nlapiLogExecution('DEBUG','script','runs 2');
var arrayName=新数组();
var arrayQty=新数组();
PORecord=nlapiGetNewRecord();
lines=PORecord.getLineItemCount('item');
POID=nlapiGetRecordId();
POTYPE=nlapiGetRecordType();
//获取名称和数量
对于(变量i=1;i
~其余未执行的代码~`

var steve=“form.setScript('customscript_toloader')”; 表单.addButton('custpage\u purchaseorder','Create TO',steve)

不确定您在这些行中要做什么,但是addButton中的第三个参数应该只是您的函数名。例如:

form.addButton('custpage_purchaseorder','Create TO','createTO')

var steve=“form.setScript('customscript_toloader')”; 表单.addButton('custpage\u purchaseorder','Create TO',steve)

不确定您在这些行中要做什么,但是addButton中的第三个参数应该只是您的函数名。例如:


form.addButton('custpage_purchaseorder','Create TO','createTO')

suitescript很奇怪。这样做会导致功能在加载时运行,而不是在按下按钮时。您确定它在加载时运行吗?我已经多次使用它,它从来没有为我加载运行,只有当按钮被点击。也许您在加载前函数中为按钮调用相同的函数。它将在加载前运行按钮中的任何参数。我发现的唯一例外是,在参数中放入一个字符串脚本,然后它将在单击按钮时工作。但是为我的函数这样做会导致它根本不运行
var steve=“函数测试(){alert('按钮是在视图模式下从“+nlapiGetRecordType()+”中单击的”);\var hi='hello';\alert(hi);}test()”suitescript很奇怪。这样做会导致功能在加载时运行,而不是在按下按钮时。您确定它在加载时运行吗?我已经多次使用它,它从来没有为我加载运行,只有当按钮被点击。也许您在加载前函数中为按钮调用相同的函数。它将在加载前运行按钮中的任何参数。我发现的唯一例外是,在参数中放入一个字符串脚本,然后它将在单击按钮时工作。但是为我的函数这样做会导致它根本不运行
var steve=“函数测试(){alert('按钮是在视图模式下从“+nlapiGetRecordType()+”中单击的”);\var hi='hello';\alert(hi);}test()”