Discussions

Expand all | Collapse all

Create a button that gets the UserID for the user in a user field and then write that information to a field in the same record

  • 1.  Create a button that gets the UserID for the user in a user field and then write that information to a field in the same record

    Posted 01-29-2019 18:19
    Hello Quick Base Community.  

    I am wanting to get the UserID for a user with the click of a button.  Using the API_GetUserInfo, I can pull the UserID, copy it and then paste it somewhere, but what I would like to do is click a button that will get the UserID and then write it to a field in the record that I am on.  

    Really the question is, is it possible to call an api and then perform an action using data that is returned from the initial api call? 

    I assume that this wouldn't be a problem using scripting but I would like to know if it is possible natively within Quick Base.

    Thanks!


  • 2.  RE: Create a button that gets the UserID for the user in a user field and then write that information to a field in the same record

    Posted 01-29-2019 18:32
    The formula for a formula user field for the current user is just

    User()

    So maybe that is all you need and not API calls.

    As for making a formula URL button, I can help you with that.  Do you just want to click a button and write the current user to a field and refresh the record?




  • 3.  RE: Create a button that gets the UserID for the user in a user field and then write that information to a field in the same record

    Posted 01-29-2019 18:45
    Ultimately I want to add a user to an app through a formula url button.  The api for that is API_AddUserToRole.  This requires the UserID which is not accessible through a formula function; at least that I am aware of.


  • 4.  RE: Create a button that gets the UserID for the user in a user field and then write that information to a field in the same record

    Posted 04-08-2019 22:20
    Forrest, I'm after the exact same thing. Did you ever find a solution?


  • 5.  RE: Create a button that gets the UserID for the user in a user field and then write that information to a field in the same record

    Posted 04-09-2019 01:27
    Try using the the email address.


  • 6.  RE: Create a button that gets the UserID for the user in a user field and then write that information to a field in the same record

    Posted 04-10-2019 04:58
    Using email in place of userid in the API_AddUserToRole call returns an invalid input error message. I can't figure out how to capture the userID via API_GetUserInfo and then pass that into a API_AddUsertoRole call. Thoughts?


  • 7.  RE: Create a button that gets the UserID for the user in a user field and then write that information to a field in the same record

    Posted 01-29-2019 18:46
    The solution might simply be to have a User field (suppose it's called "This User") in a form rule like this:

    When "This User" is ____ (empty or some other condition)
    Change "This User" to the current user (that's one of the standard options for this type of rule)

    ... oh, just saw your comment about API_AddUserToRole ... so then you have User A adding or editing a record from which they can add User B to the app in some role, is that right?

    I'll assume yes, and further assume that somewhere, probably in a different app in your Quick Base realm, User B exist (i.e., has an active, valid Quick Base login with a known email address). Let's says that it's in a table called "All Users" in an app called "My Directory".

    Then you could ...

    1. Populate a "UserID" field on every record in the "All Users" table -- by downloading from the standard User table in your app(s), extracting the IDs from that download, then uploading it into the "UserID" field. Maybe you do this with manual downloads and uploads via spreadsheets or maybe with API calls to API_GetUserInfo. Either way, the desired result is your own master table of Users and their IDs, names, and emails, with email as the key field in this master table.

    2. In the app where you want to add the user in a role, create a cross-app relationship to the "All Users" table in your "My Directory" app. Call it "New User Email" and place it on the form to get User A (the one who's editing or adding the record) to identify User B. The parent in the cross app relationship is the email key in the the "All Users" table of the "My Directory" app. Create "UserID Lookup" as a lookup field on the relationship. User A will populate the "New User Email" field with an email, and, if that email exists in the "All Users" table, then the known user's Quick Base ID visible to the app where you are adding that user in a role.

    3. When "New User Email" is filled and "UserID Lookup" is not null (i.e., User A is trying to add User B and User B is a known user in the "All Users" table of the "My Directory" app), then your button can use API_AddUserToRole.

    4. Your button formula (or a form rule) should probably hide the button when "UserID Lookup" is null.