SuiteScript – Remove Save Button

I was tasked with locking down item fulfillments. We wanted our office staff to be able to create an item fulfillment, but not edit an existing item fulfillment. I tried to lock this down through conventional security settings. Ideally, Create should have worked. But it did not. View also came up short.

Security Settings

For better or for worse, my solution was to code an event script that checked both context and role and removed buttons.

When viewing an item fulfillment, I removed the Edit button.

View no buttons

And since there are lots of ways to get into edit mode besides this button, I removed the Save button from the edit screen. It looks just like the view screen. Same buttons. Editable, but no means to save changes.

Edit no buttons

Here is the event script that removes those buttons.

Code to remove buttons

This was a pretty straightforward task. The only trick was getting the names of the buttons. To get those, I went to our sandbox and debugged an existing transaction. I stopped the code in this event script and looked at the Form object. From there I drilled into the Buttons array and read the names of all buttons. When I removed the Save button, all other child buttons (Save & Bill, Save & New, etc.) went too.

One more note. I tried to use form.getButton(‘submitter’).setDisabled(true). This did not work. The button remained present and active. This was not the case in view mode. That option worked fine and the button was grayed out and inactive. However, since I was removing buttons, I decided to be consistent and remove them all.

Here is the code in a format that you can cut and paste.

var logic_events_item_fulfill = {
BeforeLoad: function(type, form) {
var context = nlapiGetContext().getExecutionContext();
var role = nlapiGetRole();
if (context ==”userinterface”&& role ==1011) {
if (type ==’view’) {
form.removeButton(‘edit’);
}
elseif (type ==’edit’) {
form.removeButton(‘submitter’);
form.removeButton(‘resetter’);
}
}
}
,
BeforeSubmit: function(type) {
}
,
AfterSubmit: function() {
}
};

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s