3

We are programming a script on NetSuite to integrate with a third-party app.

When you access a record (whether is View or Edit) we need to determine what kind of the permission the NetSuite user has over the record.

I know by the documentation that these are the possible permission values:

  • CREATE
  • EDIT
  • FULL
  • NONE
  • VIEW

I also I know I can get the user permissions by using:

var userObj = runtime.getCurrentUser();
var permission = userObj.getPermission('ADMI_ACCOUNTING')`

The problem is that I need to know what permission to ask for specifically based on the current record I'm in. I can't find a value in the currentRecord that can allow me to ask for the permission on the user object to be able to determine the permission level the user has over the record.

Anyone that has an idea on how to pull this off I would really appreciate it!

nachoargentina
  • 730
  • 7
  • 13

1 Answers1

7

I think your best bet here is to create a helper function that maps record types to their matching permission. You'll have to maintain it manually.

It looks like you're using SS2.0, so assuming you have the N/record module available (or something comparable), you could do something like this:

function getPermissionName(recordType) {
    var objectPermissionMap = {
        customer: 'LIST_CUSTJOB',
        invoice: 'TRAN_CUSTINVC'
    };

    return objectPermissionMap[recordType];
}

var user = runtime.getCurrentUser();
var permissionName = getPermissionName(record.type);
var permission = runtime.getPermission(permissionName);
Mike Robbins
  • 3,184
  • 15
  • 20