Discussions

 View Only
Expand all | Collapse all

IOL and UserID

  • 1.  IOL and UserID

    Posted 04-09-2019 16:56
    Hello. I've added basic IOL functionality to an app, but I'm admittedly new to it. In a form, when a user dropdown changes, I want to run  API_GetUserInfo for the user chosen in the dropdown and then populate a field of the form with the user's userID. 

    Any tips would be greatly appreciated.


  • 2.  RE: IOL and UserID

    Posted 04-09-2019 18:45
    Is there a reason you're trying to use IOL versus standard user fields and form rules? Is there something specific about the User ID you need? You could user a formula-user and User() formula in combination with form rules to store the value to accomplish what it sounds like you're trying to do. 

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 3.  RE: IOL and UserID

    Posted 04-09-2019 18:55
    I have an app in which I've added @mycompany.com as a user - granting all registered users of my firm basic access to the app, which includes access to a profile table. Users can create a profile for themselves and in so doing identify the role the user should have in the app. 

    Once the form is populated sufficiently, a formula URL field button will appear in the form. The button will use the API_AddUsertoRole call. 

    I need to reference the userID in the API_AddUserToRole call. I don't know how else to get that userID short of IOL, etc.

    Thoughts?


  • 4.  RE: IOL and UserID

    Posted 04-09-2019 19:05
    To expand on my prior comment - the goal is that I don't want myself or my team to be a bottleneck of user management. There may be a lot of users coming/going into the app over time - I want them to be able to dictate their own user experience based on their profile table inputs.


  • 5.  RE: IOL and UserID

    Posted 04-09-2019 19:16
    So if I'm understanding: 
    1) User creates profile, selects role
    2) User clicks button to add themselves to that particular role

    From your original description - I'm going to go out on a limb and make an educated guess that you're going to have an issue that unless you granted everyone 'sharing' access to this app or others - they won't be able to add themselves to a new role regardless. Basically their permissions likely won't be high enough to actually apply themselves to a role - because they need 'Basic + Sharing' which opens up the 'Users' tab

    That said - another approach might be to re-think how to chain the actions together. Basically - instead of the button adding them in the role - you can use the button to make your API_GetUserinfo call - and then store the user ID in the record as a field - basically the way you want to with IOL - but this way it's user initiated. When that field is written - you could have a webhook fire - and the webhook could do the provisioning of the actual user as a background action that isn't reliant on the particular user trying to provision themselves. 

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 6.  RE: IOL and UserID

    Posted 04-09-2019 19:20
    Thanks, very much for that. I'm quite happy to do it the way you suggested, but I keep struggling at the point of extracting the userid from the API_GetUserInfo call. I don't know how to parse the userID values from the other values returned in the call. Any tips? Thanks!!


  • 7.  RE: IOL and UserID

    Posted 04-09-2019 23:03
    If you're setting it up to run from a button - you can throw some jQuery in a formula-url and make your api call - parse the response - and throw that in your field. Since your question is specific to how to get the user ID - here is an example of how you might do it in QB (using a formula-url) --

    var text url = "https://yourrealm.quickbase.com/db/main?a=API_GetUserInfo&email=youremail";
    "javascript: { 
    $.get('" & $url & "', function(response, success) {
    var userId = response.getElementsByTagName('user')[0].getAttribute('id');
    console.log(userId);
    })}"

    The $.get makes the API call - then as I typed it above should parse it out and log it to your console. From there - you can make another API_EditRecord call with another $.get request and store the true value of the userid in a field somewhere or take whatever action you need from there.


    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 8.  RE: IOL and UserID

    Posted 04-10-2019 01:12
    Hi Patrick. Since IOL is not an officially supported technique, it would be safest to try and solve things via native methodologies to ensure your application is supportable and stable long term. What you could do is create a dbpage and have a formula-URL button call that page and pass in the necessary variables for your code to execute the queries. Keeping this contained in the javascript pages without pushing JavaScript into the buttons is cleanest.

    I would also encourage you to specifically post on UserVoice about having us expose the userID in a formula since that would completely negate the need for any JavaScript.


  • 9.  RE: IOL and UserID

    Posted 04-10-2019 14:18
    Thanks, Harrison. I'm happy to explore any solution. Are you able to point me to any materials or other posts on this forum which elaborate on the approach you've described? Thanks!


  • 10.  RE: IOL and UserID

    Posted 04-10-2019 14:53
    The quickest way to get the userid but its not the full one, the .letters after it look like they can change but not sure if they only change per app? but in console you can type _fid_#.value where # is your user id field in the console and get it. so if you have some javascript running on page to run the add user to role you can grab it there but that value is the user id with the negative format so its not ideal.


  • 11.  RE: IOL and UserID

    Posted 04-10-2019 23:27
    If I'm not mistaken (I could certainly be), couldn't the code Chayce so graciously provided be embedded in a formula url button - such that at the press of a button, the code retrieves the userID and places it in a field value. That field value in turn could be referenced in a webhook, which executes the API_AddUserToRoll call. Is that right? 

    If so, I just can't figure out the code to append to Chayce's - the code that would take the retrieved userID and enter it into a field value. 

    I'm really sorry for the training wheels with this - I'm somewhat new to this kind of QB development, but I'm quite eager to learn.

    Thoughts?


  • 12.  RE: IOL and UserID

    Posted 04-11-2019 13:07
    If your question above is related to how to write to a field with the retrieved User ID - You can append another GET request in your formula-url for an EditRecord call. Not sure if thats the desire - the above comments seem to be in a different direction. If thats the need though - you can take the formula I provided above and do something along the lines of:

    var text url = "https://yourrealm.quickbase.com/db/main?a=API_GetUserInfo&email=youremail";
    "javascript: { 
    $.get('" & $url & "', function(response, success) {
    var userId = response.getElementsByTagName('user')[0].getAttribute('id');
    $.get('https://yourrealm.quickbasae.com/db/tabledbid?a=API_EditRecord&apptoken=token&_fid_10=' + userId, function(response,success) { window.location.reload() })
    })}"

    where _fid_10 would be updated specific to the actual field ID you need to store the User ID value in.

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base