shawleigh17
shawleigh17

Reputation: 1187

Custom Button to Set Fields on Form in NetSuite SS2.0

I have a custom button in NetSuite, and I am wondering if there is any way for me to set fields on the form using the button. Basically, I am going to have an approval button that will lock down editing, and I am wondering if I can do that through the button and javascript. As far as I can tell, I can't access the context of the script, since I start in the user event script and then go to the client. I might also just be missing something really dumb, but I am fairly new to NetSuite. Here is what I have in my user event script

function beforeLoad(context) {

        var form = context.form;
        form.clientScriptModulePath = './_kk_fc_cs_sd.js';

        form.addButton({
            id           : 'custpage_china_approve_btn', 
            label        : 'Approve - China', 
            functionName : 'chinaApproveFinalQuote'
        });
        form.addButton({
            id           : 'custpage_dallas_approve_btn', 
            label        : 'Approve - Dallas', 
            functionName : 'dallasApproveFinalQuote'
        })
}

and then for my client script i have

function chinaApproveFinalQuote()
    {
        alert(record.id);
        var firstCost = context.currentRecord;

        firstCost.setValue('custrecord_kk_sd_fc_master_carton_cb', true);
    }

It pretty much has no idea what context is. I tried passing it in the user event script, and also tried to use record.id, but neither of those worked. Any idea, or do I have to go about this a different way?

Upvotes: 0

Views: 3179

Answers (2)

Todd Grimm
Todd Grimm

Reputation: 544

The issue you are having is because you need to use the currentRecord in the client script in order to set/get values. One other thing to note here is that if you are only referencing the client script via its NetSuite folder location (not actually deployed to the record), you still need to include a pageInit entry point function (it can be empty though). Just another SuiteScript 2.0 caveat...

/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */
define(
    [
        'N/currentRecord'
    ],

    function (
        nsCurRec
    ) {

        function chinaApproveFinalQuote() {
            var btn;
            var rec = nsCurRec.get();

            alert(rec.id);
            btn = rec.getField('custpage_china_approve_btn');
            btn.isDisabled = true;
            rec.setValue({
                fieldId: 'custrecord_kk_sd_fc_master_carton_cb',
                value: true
            });
        }

        function pageInit(context) {

        }

        return {
            pageInit: pageInit,
            chinaApproveFinalQuote: chinaApproveFinalQuote
        };
    }
);

Upvotes: 2

bknights
bknights

Reputation: 15367

Although you can do it this way (look at the relation ship between the client and user scripts in SS2.0 Display Message on Record this is an area where workflows tend to excel

Workflows have methods for locking records except for particular users; showing approve/reject buttons for particular users; setting fields etc on approval.

Upvotes: 1

Related Questions