I’m trying to get the NAME of the role of the curr...
# suitescript
j
I’m trying to get the NAME of the role of the current user via RestLET. Is this possible? I can get the internalid (e.g. 1017) and id (e.g. customrole1017)
e
Using query;
Copy code
function getRoleName(roleId) {
                return query.runSuiteQL({query: `SELECT ROLE.name FROM ROLE WHERE ROLE.ID = ${roleId}`}).results[0].asMap().name;
            }
s
Also, you could use lookupFields for slightly less governance cost (not sure if it matters):
const { name: roleName } = search.lookupFields({ type: 'role', id: 1017, columns: ['name']});
OR
const roleName = search.lookupFields({ type: 'role', id: 1017, columns: ['name']}).name;
👍 1
j
but it’s not running as admin so doesn’t have access to
role
table
RESTlets run w/role of current user
you cannot do “run as Admin”
s
yeah, you’d have to grant view permission to role, otherwise neither of these methods work
hacky solution: you could have a Suitelet that runs as Adminsitrator, and available without login. Have the Suitelet take a role id and return the name. For some added security, require some additional parameters and values so a random request without those secrets will get nothing.
j
I need a generic solution 😞
Yeah that’s what I’m gonna do I think
s
well it is generic, but far from ideal. Improved hacky version: put the ids & roles into a long-lived global cache, and check the cache first, before calling the Suitelet.
unless you change role names often in your account, in which case, don’t do that
j
sorry with the generic I meant something where I wouldn’t have to remember to add “role” access to every role moving forwards
^^^ worst sentence ever
😂 2
I’ll go with the RL calls SL solution I think
s
We had to do something like this once for a restlet that needed to check credit card expiration dates, and apparently, very specific permissions were needed for that, and not something we wanted to give everyone, so we used this approach to fudge it.
An alternative solution: It may be possible to use SuiteTalk to do the lookup. I avoid SuiteTalk like the plague, though, so I don’t even know if it possible, but perhaps worth looking into.
c
Could you expose a saved search and run that and just get the ID and name in a lookup and whatever role just look it up in the object.
s
I just tested it and you’d need to give permission to individual roles from the saved search itself. Doable, but if you add new roles in the future, you’d have to update the search
c
Could also generate a list once per day and save it as a file in a folder everyone has permissions for and have the restlet just read that file. A little more involved as you'd need 1 script that generates X times per day (once is probably more than enough) and the other script just reads that file and makes the lookup object. Then you can
just throwing out some ideas
j
got to work with the RESTlet calls SuiteLet approach
convoluted….hahhah
thanks for the advice
s
half my NetSuite customizations seem to involve some convoluted crap to workaround a limitation …
netsuite 1
I’m almost surprised when they don’t, tbh
netsuite 1
j
same! I always seem to get 95% of the way to a solution and then have to detour to some “hack” to get to the finish line.
netsuite 1
s
Yeah, I used to frustrate my manager when he’d ask me for a status and I’d be like, I’m 90% done except for this one todo that I couldn’t figure out for some reason. Only to revisit that TODO and discover I needed to build a whole solution for it that took just as long. Case in point, we wanted to be able to translate emails, but still use email templates. I discovered that the bodies of the emails could easily be modified to translate on their own. The subjects however …. not so much. Had to design my own email rendering module to replace N/email just for the email Subjects. All for one little line of text.
😫 1
r
My favorite is when I have to do a bunch of hacky things to perform a test without going thru a bunch of useless admin tasks in the SB, I know that it will work in production, but QA/UAT just ain't happening. lol
j
grumble grumble
🤭 1
n
Look at it this way, if it was simple, arguably you'd not be paid as well 😉
j
You assume I’m paid well
n
"CTO" and NOT paid well, get out of there...
j
Oh I should update that. My title isn’t CTO anymore cuz we got acquired….
when we were a small company I was the whole tech department, thus was CTO by default hahhah.
For clarity, I’m ok with my current salary. I could get more elsewhere, but I really love my team and the work I get to do. That’s massively valuable to me, having had a very different experience at my last job.
n
Yup definitely more to a role than just salary. I'm fortunate to be paid well and work in a company that is very supportive and I work with some amazing people. It would take a lot to prise me away at this time.
c
at a certain point it really doesn't matter and is more trouble that its worth. Would another 10-20k/yr majorly change you life? and if so, is it worth what they are about to ask you to do?
💯 1
(imo)