is it possible to script out the Edit button on a ...
# suitescript
u
is it possible to script out the Edit button on a record if the current User isn't the Owner of the record? Using SS2 if possible.
e
You could use a workflow and lock the record
d
Yes it's possible, there's a remove function somewhere and you can check ID of logged in user.
u
@Daniel Lloyd After further reading, I don't think you can specifically remove the Edit button among the list of buttons you could remove, though fetching the ID of the current user isn't that hard. Netsuite probably leaves it accessible on purpose. @ehcanadian I'd like it so that the record would unlock if the user was the owner though, would it be possible to "unlock" a locked record that's being locked by a workflow?
d
Pretty sure I did form.removeButton({id:”edit”})
2
Might need “submitedit” too
u
@Daniel Lloyd I gave it a try, and surprisingly it worked. I initially wrote it off since checking the SS2 API pdf, the Button id's never indicated anything for the Edit button, though I guess that's something they wouldn't want people removing unknowingly. Thanks for this.
d
Yep, there's plenty of undocumented functionality. It's just vulnerable to being pulled out/unsupported and needs that assessment before being implemented in a business.
m
This method doesn't prevent the user from adding
&e=T
to the URL and editing the record anyway. As ehcanadian mentioned above, using a workflow with the lock record action would work and no scripting required.
u
@Mike Robbins I see. Am I correct to assume I can conditionally "lock" and "unlock" it based on the current User through workflows? From what I've been reading on it, locking records through workflows seem to be a one-way thing, though this might be another case of undocumented features not being written down.
m
@7px Yes. You can apply conditions to the "Lock Record" action so that it only applies if the current user is the owner of the record. Locking a record only applies while the record is in a workflow state that contains the Lock Record action. As soon as the record transitions to another state without that action, the record is unlocked. It's not a permanent status by any means.
1
n
You can stop them doing &e=T on a user event before load, you make the relevant checks on EDIT and redirect back to the opened record with it set to view. It's trivial to do.
Also as for button IDs in help...
Copy code
if (context.type === context.UserEventType.EDIT) {
    redirect.toRecord({
        type: record.Type.VENDOR_BILL,
        id: context.newRecord.id,
        isEditMode:false
    });
}
You will want to preface this with any logic you need to determine that you do not want it editing. (you could also use context.newRecord.type for "type" above)