Forum Discussion

SterlingLong1's avatar
SterlingLong1
Qrew Trainee
6 years ago

Create a Role using QB API's

Hey guys!

I am trying to create a role automatically whenever a new record is added to a table.
Sadly, and for some reason, this is the only thing that the QB APIs doesn't have access to.
Does anyone know of a way to do this? Or will I have to manually create the roles for each record?

Any responses are welcome, thank you!

------------------------------
- Sterling Long!
------------------------------
  • I will make you a deal. If you promise not to make an app with so many roles, I will promise to find a solution that does not need to have many roles. 

    Can you describe why why you feel you need so many roles?

    ------------------------------
    Mark Shnier (YQC)
    Quick Base Solution Provider
    Your Quick Base Coach
    http://QuickBaseCoach.com
    markshnier2@gmail.com
    ------------------------------
    • SterlingLong1's avatar
      SterlingLong1
      Qrew Trainee
      We are making an app that we will be selling as a service to multiple companies. Each company has access to only their information, and we have a system set up that will filter out information that isn't there based on the role that they were given.
      Essentially we need some way to filter their information so they only see their information and no one elses.

      For each company there will be two types of people, and possibly others in the future: Admin and Normal.
      The best way we have thought to do this is with roles, and what we have works, we just have to make each role manually, which takes time and is prone to errors, which is why I wanted to use an API to make it happen automatically.

      What are your thoughts? This is the only way we could think of to silo the information in the way we needed.

      ------------------------------
      Sterling Long
      ------------------------------
      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend
        That is what I suspected. But when i get a chance I will honor my promise.  If you promise not to do a brute force solution with a zillion Roles,  I will post back with how to do this with 1 Role. .. later today.   Gotta run to meetings now.

        ------------------------------
        Mark Shnier (YQC)
        Quick Base Solution Provider
        Your Quick Base Coach
        http://QuickBaseCoach.com
        markshnier2@gmail.com
        ------------------------------
  • Sterling,

    Please follow up with Mark.   You do NOT want those Roles! 

    His solution will be much more elegant and easier for you to maintain.


    ------------------------------
    Don Larson
    Paasporter
    Westlake OH
    ------------------------------
    • MarkShnier__You's avatar
      MarkShnier__You
      Icon for Qrew Legend rankQrew Legend
      OK, here's the setup.

      Create a table of Users where the Key field is userid.  Let's call the table Users Limited By Company.
      Create relationship where One Company has many Users. Great, now each userid knows the Company they need to be limited to.

      Here is the magic. 

      Create a relationship where 1 Userid in that table has Many "records".  If there are multiple tables which need to be limited you will need to do this for each table.  Let's say the table being Limited is "Orders".  OK so One User has many Orders.   Change the reference field on the right side of the relationship  from being called Related User to be called [Current User] .  Of course you know that just calling a field [Current User] don't make it actually be [Current User] so we change this to a formula user field with the formula of 

      User()

      That function returns the current user.

      That's the very kernel of the magic that only Quick Base can do.  So now look up Company from that relationship down to Orders, ie that will be the Company for the hands on keyboard current user,.

      Make a formula checkbox field called [User allowed to see this company?]

      IF([Company] = [Current User Company], true)

      Now set up just 1 Role for regular users limited by company and set the Custom rules to only be able to see Orders where [User allowed to see this company?] is checked.

      If you need a higher level Role with Share permissions, then go ahead  and duplicate that Role but use the same type of Customer Rule to limit access.  Note also that if you need that field on any child records of orders, say Order Line, you can just look up that fiel form the parent and make a similar Customer Permission Rule

      Voila, one role (except you need  two due to different Share permissions.



      ------------------------------
      Mark Shnier (YQC)
      Quick Base Solution Provider
      Your Quick Base Coach
      http://QuickBaseCoach.com
      markshnier2@gmail.com
      ------------------------------
      • SterlingLong1's avatar
        SterlingLong1
        Qrew Trainee
        Ok so essentially construct the “roles” by checking current user and their related company, then make sure each record has a company field and make sure the company fields match using that formula? Did I follow that correctly?

        I will look into this some more later tonight. Thank you for the response!

        - Sterling Long

        ------Original Message------

        OK, here's the setup.

        Create a table of Users where the Key field is userid.  Let's call the table Users Limited By Company.
        Create relationship where One Company has many Users. Great, now each userid knows the Company they need to be limited to.

        Here is the magic. 

        Create a relationship where 1 Userid in that table has Many "records".  If there are multiple tables which need to be limited you will need to do this for each table.  Let's say the table being Limited is "Orders".  OK so One User has many Orders.   Change the reference field on the right side of the relationship  from being called Related User to be called [Current User] .  Of course you know that just calling a field [Current User] don't make it actually be [Current User] so we change this to a formula user field with the formula of 

        User()

        That function returns the current user.

        That's the very kernel of the magic that only Quick Base can do.  So now look up Company from that relationship down to Orders, ie that will be the Company for the hands on keyboard current user,.

        Make a formula checkbox field called [User allowed to see this company?]

        IF([Company] = [Current User Company], true)

        Now set up just 1 Role for regular users limited by company and set the Custom rules to only be able to see Orders where [User allowed to see this company?] is checked.

        If you need a higher level Role with Share permissions, then go ahead  and duplicate that Role but use the same type of Customer Rule to limit access.  Note also that if you need that field on any child records of orders, say Order Line, you can just look up that fiel form the parent and make a similar Customer Permission Rule

        Voila, one role (except you need  two due to different Share permissions.



        ------------------------------
        Mark Shnier (YQC)
        Quick Base Solution Provider
        Your Quick Base Coach
        http://QuickBaseCoach.com
        markshnier2@gmail.com
        ------------------------------