Hi All, I want to create an Button Approve that wi...
# suitescript
a
Hi All, I want to create an Button Approve that will aprrove the sales Order and also add default values to some fields. Can anybody let me know how can it be done ? Is it possible to change the Standard Aprrove Button in Netsuite.
b
use the beforeLoad entrypoint of a user event script to add client script to the order and add a button that uses the client script
your client script function should use N/record to change the
orderstatus
field and whatever other fields you wanted to set
a
Hey @battk Thank you very much for the response. Could you please provide me any reference / resource of how can I add client script to the order using user event script ?
b
they differ in how they use the button, one uses what is essentially eval to run a string as code
the other uses the string as a function name to call instead
a
Ok @battk Thank you very much for the help. Appreciate it 👍
Hey @battk Please can you let me know how can I approve a Sales Order using Client Script. I am able to call Client Script using User Event Script. The Things I need to accomplish in using Client Script when an Button is Clicked is : 1. Approve the Sales Order. 2. Populate few body level and line level fields.
a
Hey @battk I am changing the orderstatus (to - Pending Fulfillment) & saving it but still when I refresh the record it is same as pending approval. Here's the Code for your reference :
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */
define(['N/record', 'N/log'],function (record, log) {
        function onButtonClick(internalid) {

            let rec = record.load({
                type: record.Type.SALES_ORDER,
                id: internalid
            });

            rec.setValue({
                fieldId: 'orderstatus',
                value: 'Pending Fulfillment'
            });

            log.debug({
                title: 'Order Status',
                details: rec.getValue({fieldId: 'orderstatus'})
            });
            
            rec.save();
        }

        function pageInit(context) {
            alert('PageInit');
        }


        return {
            pageInit: pageInit,
            onButtonClick: onButtonClick
        };
    }
);
Hey @battk do you how can we reload the record after making all the changes. For example when I am changing the Orders Status of the record and saving it. It get's reflected only when I reload the page, is there some way to reload the page after making all the changes.
b
a
@battk Thanks a lot, appreciate it 👍