This topic contains 11 replies, has 0 voices, and was last updated by karenn 7 years ago.

  • Author
    Posts
  • #17861

    karenn

    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 = ‘
    ‘;

    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 = ‘
    ‘;

    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 = ‘
    ‘;

    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 = ‘
    ‘;

    form.insertField({

    field: btnCalcWeight,

    nextfield: ‘custbody_pe_totalweight’

    });

    }

    return {

    beforeLoad: beforeLoad

    //beforeSubmit: beforeSubmit,

    //afterSubmit: afterSubmit

    };

    });

    Any help would be appreciated. Thanks!
    This is a cached copy. Click here to see the original post.

  • #17862

    jmkplessers

    Your onclicks expect functions in the global namespace, but in my experience SuiteScript 2.0 client scripts do not export their functions to the global namespace.

    When you add a button to the form using form.addButton its onclick() calls require() on a client script added to the form using form.clientScriptModulePath.

    E.g., this suitescript creates the following html (edited for clarity)

    Code:
    // user event
    form.clientScriptModulePath = ‘/SuiteScripts/path/to/clientscript’;
    form.addButton({
    id: ‘custpage_btn’,
    label: ‘example’,
    functionName: ‘example_function’
    });

    Code:

    You will either have to change your inline html buttons to access your client script in a similar manner, add the functions to the global namespace, or write the function code inline with the html.

  • #17863

    karenn

    I wish we could use the addButton function but that does not seem to allow you to place the button in the body of the form, just at the top and bottom with the other NetSuite buttons.

    2.0 is extremely annoying sometimes

  • #17864

    pcutler

    Not sure what your layout looks like, but you can also use nlobjSubList.addButton to add a native NetSuite button to a SubList if that position would make sense for your use case.

  • #17865

    karenn

    We have working 1.0 code to add our custom button where we want it. Need 2.0 solution unfortunately. Thanks!

  • #17866

    pcutler

    My mistake, the SS 2.0 API method is Sublist.addButton(options). It doesn’t give you the option to add a button anywhere on the page like you can with an inline HTML field, but it does give you one additional place on the page to add a button that could potentially work with your layout.

  • #17867

    karenn

    Looks like adding a couple of them to sublist buttons might work but 2 of the buttons are under the Shipping tab, no sublist

    Sometimes I feel like we are taking 10 steps backwards with 2.0

  • #17868

    jmkplessers

    Hey sorry if I was unclear. I was trying to explain why the “official” addButton works but your current script does not.

    Just change your onclick like so and it should work (be sure to use the real file cabinet path).

    Code:
    onclick=”require([‘/path/to/pe2_cs_quote’], function(client) { client.onclick_showPriceList(); });”
    instead of

    Code:
    onclick=”onclick_showPriceList();”

  • #17869

    karenn

    Thanks but no joy

  • #17870

    karenn

    For the path are you using the url from the script that NetSuite gives you in the script file record?

  • #17871

    jmkplessers

    Path is the location of your client script in the file cabinet.

    So if your client script is in the “SuiteScripts” folder the path would be “/SuiteScripts/pe2_cs_quote”.

    If your client script is in the “cs_quote_project” folder in the “SuiteScripts” folder the path would be “/SuiteScripts/cs_quote_project/pe2_cs_quote”.

  • #17872

    karenn

    Well, thought I had tried that but now it is!!! Thanks for all the help. On to the next problem

You must be logged in to reply to this topic.