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.
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.
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.
Here is the event script that removes those 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.