Capture Current User's role in formula text field?

  • 0
  • 1
  • Question
  • Updated 3 months ago
  • Answered

Hello QB Community,

Has anyone devised a way to capture the current user's role in a formula field?

I currently use form rules to discern a user's role, but I have to create a form rule for every possible role, and this method also requires maintenance.

Nice to have a dynamic way to capture the user's role as it appears in the QB list of roles for a particular app, then do a thing after it has been captured.

Thanks for any help,

Chris

Photo of Chris

Chris

  • 4,430 Points 4k badge 2x thumb

Posted 4 years ago

  • 0
  • 1
Photo of Rama

Rama

  • 0 Points
There is a variable within the HTML of the page, so if you can use JavaScript you can get the role ID and then go from there.

It is stored in the page as gReqUserRoleID. You can get the roleID's from the role page and go from there.  I would just grab the value, do a case statement, then return what you need in the formula field
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
There are no formula function that will return the user's role. Moreover, a user can be in multiple roles at once so any potential function would have to return all roles.

However you can obtain this information using script and the API method API_GetUserRole. Here is the XML Response for me calling API_GetUserRole on an application where I am in both the Administrator role and Basic Access with Sharing role:

http://pastie.org/10331624


Since there is an API method that returns this information you should use it an not dip into the pool of Global Variables where QuickBase for its own purposes has some of the same information in the source of its pages. But on the other hand there is no harm in poking around and understanding what global variables are within QuickBase pages. See the attached screenshot of the developer console where three global variables that contains role related information and logged.

Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=439


R>I would just grab the value, do a case statement ...

If there was no API method that returned the roles (but there is), I would use underscore and gReqUserRoleIIDs (plural) the object gRofo to return all the roles the current user is a member of.
Photo of Nick Wade

Nick Wade

  • 174 Points 100 badge 2x thumb
Is there a way to utilize information retrieved from an API in a formula field?
(Edited)
Photo of Patrick Dunn

Patrick Dunn

  • 370 Points 250 badge 2x thumb
Nick, did you ever figure this out?
Photo of Nick Wade

Nick Wade

  • 174 Points 100 badge 2x thumb
You can use this method in an IOL script like Dan describes above, but you cannot permanently place the value into a field via this technique. Because of this, it cannot be used in automations, notifications, or formula fields (at least as far as I understand it).
Photo of Chris

Chris

  • 4,430 Points 4k badge 2x thumb
Can you 'show' me how to apply it?