Client Scripts only run in Edit mode
# suitescript
e
Client Scripts only run in Edit mode
z
except if it is added in BeforeLoad function...
e
That wouldn't be a Client Script, then
s
I need a button the has the function to print and print label
this is from suite answers
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */
define(['N/record'], function(record) {
            function printMeNow() {
                var id = = record.id;
                show_preview(document.forms['main_form'].orderid.value, id); //Standard Print Button on Item Fulfillment
                print_shipping_label(document.forms['main_form'].orderid.value, id); //Standard Print Label Button on Item Fulfillment
                window.open('/app/accounting/print/barcodeprinter.nl?trantype=itemfulfillment&tranid=' + id); // Standard Print Item Labels Button on Item Fulfillment
            }
        }
z
I know what you mean,. but I didn't say that. In BeforeLoad fumction you can link client script file with form in any mode (View, Edit...) At the same time, add button to form with property FunctionName. When you click the button in View mode (if you want that) NetSuite will execute client script
s
@Sim Greenbaum Add the button in a user event, then call the client script function in the creation of the button.
👍 1
a
You can also add the button and embed a function to the button onclick event and you would not need a client script at all. No even attached to the form.
s
Yeah I actually prefer that method ^
z
Copy code
function beforeLoad(scriptContext) {
		var form = scriptContext.form;

		form.clientScriptModulePath = "./xxx_bstmt_cs.js";

		if (scriptContext.type == scriptContext.UserEventType.VIEW) {
			form.addButton({
				id : "custpage_submit_parser_button",
				label : 'Parse',
				functionName : 'submit_parser()'
			});
Crete all functions inside client script file and don't forget to add function name in return object
Copy code
return {
        pageInit: pageInit,
        submit_parser : _submit_parser,
        submit_payments : _submit_payments,
        submit_lookup : _submit_lookup
//        fieldChanged: fieldChanged,
//        postSourcing: postSourcing,
//        sublistChanged: sublistChanged,
//        lineInit: lineInit,
//        validateField: validateField,
//        validateLine: validateLine,
//        validateInsert: validateInsert,
//        validateDelete: validateDelete,
//        saveRecord: saveRecord
    };
s
@alien4u that is what i have now a button that on click fires my script above , however the button is only available in edit mode
s
Is the button being created on the User Event script?
Copy code
context.form.addButton({
    id: 'custpage_clickme',
    label: 'Click Me',
    functionName: `(() => {
                var id = context.newRecord.id;
                show_preview(document.forms['main_form'].orderid.value, id); //Standard Print Button on Item Fulfillment
                print_shipping_label(document.forms['main_form'].orderid.value, id); //Standard Print Label Button on Item Fulfillment
                window.open('/app/accounting/print/barcodeprinter.nl?trantype=itemfulfillment&tranid=' + id); // Standard Print Item Labels Button on Item Fulfillment
            })()`
});
should be really close to what you need on beforeLoad UserEvent (assuming 2.1 bc of syntax)
s
i need to make sure the item fulfillment is after saved
1
meaning this button should only show up after the fulfillment has been saved
s
If you are accessing the record then it's already been saved; if you are saying you don't want the button in before the record has already been created, then check the
context.type
against
context.UserEventType.CREATE
at beginning of script before adding the button.
z
@Sim Greenbaum I sent you above pieces of scripts how to create button only in VIEW mode, and how to provide client script function... Feel free to contact me if. you need more details and instructions