This topic contains 3 replies, has 0 voices, and was last updated by david.smith 7 years, 9 months ago.

  • Author
    Posts
  • #1268

    karenn

    Hello all,

    In SuiteScript 1.0 we were able to add buttons to NetSuite forms in inline html fields. These buttons would then usually bring up a window with some other info. So now I am trying to do the same type of thing 2.0.

    I have a User Event script and the button is showing up on the form.

    function beforeLoad(scriptContext) {

    //Components button

    var newInlineHtmlField = scriptContext.form.addField

    ({id: ‘custpage_pe_componentsbtn_inline’,

    type: ‘inlinehtml’,

    label: ‘ ‘

    });

    newInlineHtmlField.defaultValue = ‘
    ‘;

    scriptContext.form.insertField({field: newInlineHtmlField, nextfield: ‘printitems’});

    }

    Then like before we have a Client Script with a function to open the window when the button is clicked. Problem is nothing happens. I added an alert just to see if function was even being called and nothing happens. I also added an alert in the init function to make sure the script was attached to the form and it is. Any ideas why the onclick function is not being called?

    function onclick_showComponentList()

    {

    alert(“in”);

    var strCurItem = currentRecord.getField({fieldId: itemid})

    window.open(“http://tools.parts-express.com/QIL/QuickItemLookup.aspx?item=” + strCurItem + “&source=so”, “_blank”, “width=1500, height=800, top=100, left=50, scrollbars=yes”);

    }

    FYI, we want this button in a specific place on the form not at the top and bottom with other NetSuite buttons. That is why using the inline html.

    Thanks all!!!

    Karen
    This is a cached copy. Click here to see the original post.

  • #1269

    david.smith

    Try putting your onclick_showComponentList function in the return value with the pageInit entry functions.

    Or you could define you function as a global function on the page with something like “var window.onclick_showComponentList = function()….”

  • #1270

    karenn

    Here is everything in the client script. Already have it in the return value. I am probably missing something really simple.

    /**

    * @NApiVersion 2.x

    * @NScriptType ClientScript

    * @NModuleScope SameAccount

    */

    define([‘N/currentRecord’],

    function(currentRecord) {

    /**

    * 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 Components list to show qty onhand

    ************************************************** ************************************************** *************************************************/

    function onclick_showComponentList()

    {

    alert(“in”);

    //var strCurItem = nlapiGetCurrentLineItemText(‘item’, ‘item’);

    var strCurItem = currentRecord.getField({fieldId: itemid})

    window.open(“http://tools.parts-express.com/QIL/QuickItemLookup.aspx?item=” + strCurItem + “&source=so”, “_blank”, “width=1500, height=800, top=100, left=50, scrollbars=yes”);

    }

    return {

    pageInit: pageInit,

    onclick_showComponentList: onclick_showComponentList

    };

    });

  • #1271

    david.smith

    To me, this seems really stupid, but try something like this. This is how I did a custom button on the page of a suitelet. I’m sure there is a better way.

    Code:
    onclick=”require([‘/SuiteScripts/’], function(mod){mod.onclick_showComponentList(someparam);}; return false;”

You must be logged in to reply to this topic.