Saturday, October 6, 2018

Restrict a Role's permission via Script to be able to Edit a Record but not Create a new one

 

On the Help Guide, these are the Permission Levels that could be set on a Role for a record:
 CREATE - User can create new and view existing files.
 EDIT - User has access to create new, view existing, and edit existing files. The user cannot delete existing files.
 FULL - User has access to create new files and view, edit, and delete existing files.

Thus, having the EDIT only mode is still an Enhancement and this is filed under Issue# 88524 - "Roles/Permissions > Please add an Edit Only permission so that users can edit records but not add new ones."

This can be done via script by restricting a User's action on beforeLoad function of a User Event script.

Here is a code snippet sample for restricting a Role on creating a new record:

-------------------------------------------------------------------------------------------------
// Get the User's role
var ACCESS_ROLE = nlapiGetRole();

//This example restricts all non-Administrator roles in being able to create a new record.

function TestBeforeLoad(type){

   if (ACCESS_ROLE != 3 && type == 'create') {
  
   throw nlapiCreateError('Action not allowed', 'Your role is not permitted to Add this type of Record. <br><br> Please click <a href="javascript:history.go(-1)">here</a> to go back.');

   // This throws an Error for the user that Creating a new record is not allowed. User can click on the message to go back to the previous page. 
  
   }

}

-------------------------------------------------------------------------------------------------

**Note that on this example, the Role's permission on the record is set to 'EDIT'.

DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Netsuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.

Netsuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Netsuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.

Netsuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

No comments:

Post a Comment