In 1.0 we have a User Event and Client script that create buttons in a transaction form in the body of the form using an inlinehtml field. Has worked great. We want to make some changes/additions to the script and want to rewrite in 2.0.
So, I have created a User Event and Client script in 2.0 and the buttons are showing up but the on_click events are not firing and I have no idea why. I am probably forgetting something. Here is the code
Client Script
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord'],
function(currec) {
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
function pageInit(scriptContext) {
}
/****************************************************************************************************************************************************
* function to pop up price list for item on sales order form. It is passing the item number from the current item list line, i.e. the one they
* are editing
*****************************************************************************************************************************************************/
function onclick_showPriceList()
{
alert("price list");
}
/****************************************************************************************************************************************************
* function to pop up Quick Item Lookup for order
*****************************************************************************************************************************************************/
function onclick_showQIL()
{
alert("QIL");
}
/****************************************************************************************************************************************************
* function to pop up shipping options for order
*****************************************************************************************************************************************************/
function onclick_showShipOptions()
{
alert("shipping");
}
/****************************************************************************************************************************************************
* function to calculate order weight
*****************************************************************************************************************************************************/
function onclick_calcWeight()
{
alert("calc weight");
}
return {
pageInit: pageInit,
onclick_showPriceList: onclick_showPriceList,
onclick_showQIL: onclick_showQIL,
onclick_showShipOptions: onclick_showShipOptions,
onclick_calcWeight: onclick_calcWeight
};
});
User Event Script
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/ui/serverWidget'],
function(ui) {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type
* @param {Form} scriptContext.form - Current form
* @Since 2015.2
*/
function beforeLoad(scriptContext) {
form = scriptContext.form;
form.clientScriptFileId = 64148; //internal id of actual js file in filecabinet - pe2_cs_quote.js
//add Price List Button
var btnPrice = form.addField({
id: 'custpage_pe_pricelist_inlinebtn',
type: ui.FieldType.INLINEHTML,
label: 'price'
});
btnPrice.defaultValue = '<br/><input id="btnPEPriceList" onclick="onclick_showPriceList();" type="button" name="btnPEPricList" value=" Price List 2 " style="width:150px; height:30px; cursor: pointer; background-color:#378FFA;border:1px solid #9DBFF2; color:#FFFFFF; font-weight: bold;">';
form.insertField({
field: btnPrice,
nextfield: 'discountitem'
});
//add QIL button
var btnQIL = form.addField({
id: 'custpage_pe_qil_inlinebtn',
type: ui.FieldType.INLINEHTML,
label: 'QIL'
});
btnQIL.defaultValue = '<br/><input id="btnPEQIL" onclick="onclick_showQIL();" type="button" name="btnPEQIL" value=" Quick Item Lookup 2 " style="width:150px; height:30px; cursor: pointer; background-color:#378FFA;border:1px solid #9DBFF2; color:#FFFFFF; font-weight: bold;">';
form.insertField({
field: btnQIL,
nextfield: 'discountitem'
});
//add Shipping Options button
var btnShip = form.addField({
id: 'custpage_pe_ship_inlinebtn',
type: ui.FieldType.INLINEHTML,
label: 'ship'
});
btnShip.defaultValue = '<br/><input id="btnPEShipOptions" onclick="onclick_showShipOptions();" type="button" name="btnPEShipOptions" value=" LTL Options 2 " style="width:150px; height:30px; cursor: pointer; background-color:#378FFA;border:1px solid #9DBFF2; color:#FFFFFF; font-weight: bold;">';
form.insertField({
field: btnShip,
nextfield: 'shippingcost'
});
//Calc Weight button
var btnCalcWeight = form.addField({
id: 'custpage_pe_calcweight_inlinebtn',
type: ui.FieldType.INLINEHTML,
label: 'calcweight'
});
btnCalcWeight.defaultValue = '<br/><input id="btnPECalcWeight" onclick="onclick_calcWeight();" type="button" name="btnPECalcWeight" value=" Calc Weight 2 " style="width:150px; height:30px; cursor: pointer; background-color:#378FFA;border:1px solid #9DBFF2; color:#FFFFFF; font-weight: bold;">';
form.insertField({
field: btnCalcWeight,
nextfield: 'custbody_pe_totalweight'
});
}
return {
beforeLoad: beforeLoad
//beforeSubmit: beforeSubmit,
//afterSubmit: afterSubmit
};
});
Any help would be appreciated. Thanks!