Get an XML result from an API call into a field as a value

  • 0
  • 1
  • Question
  • Updated 1 month ago
  • In Progress
  • (Edited)
I have a formula button that returns the User ID of a user based on their email address.  I'm getting the result in an XML page and want to pass it to a field called User ID.

Here's the formula that gets me the User ID.

Here's the result it returns.

How can I edit the formula to make the API call and pass the <user id="xxxxxx"> result to a field in one swoop?  I need this result in order to complete a button I'm using to send an invitation to the app.  The user ID is my missing link, which will pull this all together.

Thanks for any help you can offer.

Dana
Photo of Dana Hauser

Dana Hauser

  • 424 Points 250 badge 2x thumb
  • Almost there

Posted 1 month ago

  • 0
  • 1
You have to reconfigure the way you're making the call to use Javascript instead of just a formula url. Basically you have to make the call, interpret the raw XML and then make a secondary API call to do an EditRecord or API_SendInvitation. 

If you're using a standard URL button - you can inject Javascript like so:

javascript: {
$.get( api call to get user id , function(data,success) {
var userid = parse xml response;
$.get( make your editRecord call with the userid var );
}) 
}

the first $.get request makes the initial API call. Then, once that returns successfully, you parse the response, then make a second API call using that response data, and then you have the desired effect.

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

Dana Hauser

  • 424 Points 250 badge 2x thumb
Thank you Chayce!  I figured it might be something along those lines.  I'll give it a try and see what I can come up with..

Dana
Hey Dana - feel free to reach out via email or this thread if you need any assistance. The syntax with single quotes versus double quotes for Quick Base gets tricky, more annoying than anything. So keep that in mind when working within your JS - everything should be kept within single quotes if possible


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

Dana Hauser

  • 424 Points 250 badge 2x thumb
Thanks Chayce, I certainly will.  I really appreciate your help.

Dana
Photo of Dana Hauser

Dana Hauser

  • 424 Points 250 badge 2x thumb
Chayce,

I'm stuck on the parsing the xml return of the User ID.  Can you elaborate on that further?

Thanks,

Dana
Dana - see the below as one way to get the User Id

"javascript: {" & 
  "$.get('" & $urlU & "',function(data,success) {" & 
        "console.log(data);" &
        "var user = data.getElementsByTagName('user')[0].getAttribute('id');" & 
        "console.log(user);" & 
        //"$.get('" & $urlE & "' + user);" & 
  "});" &   
"}"

In this case - I've declared urlU as the getUserInfo API call - then the User Id gets stored in a variable 'user' in the actual JS line. I've commented it out - but the second $.get is where you can set up your Edit Record call and include the user variable as part of the call

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

Dana Hauser

  • 424 Points 250 badge 2x thumb
Chayce,

Am I on the right track here?

var text urlU= "https://xxx.quickbase.com/db/main?a=API_GetUserInfo&email="; & [Email];
"javascript: {" & 
  "$.get('" & $urlU & "',function(data,success) {" & 
        "console.log(data);" &
        "var user = data.getElementsByTagName('user')[0].getAttribute('id');" & 
        "console.log(user);" & 
var text urlE= URLRoot() & "db/" & Dbid() & "?act=API_EditRecord" & "&rid=" & [Record ID#] & 
"&apptoken=xxxxxx" 
& "&_fid_435="; 
        "$.get('" & $urlE & "' + user);" &
  "});" &   
"}"

Thanks,

Dana
(Edited)
Photo of Dana Hauser

Dana Hauser

  • 424 Points 250 badge 2x thumb
Wow!  I just realized it was working, I had to refresh the page in order to see it.  

I'll have to tweak it a little, but this is exactly what I was trying to do.

Thanks so much for your help Chayce, this is great.
Ah - Great!

If you want to force a refresh - after you make your editRecord call - you can do a window.location.reload() to force the page to refresh too. 

so
$.get();
window.location.reload();


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

Dana Hauser

  • 424 Points 250 badge 2x thumb
Nice!  That is in place and does the trick.
Dana - that looks spot on. I copied it over to QB just to check syntax - but it all looks right on point. Have you tested yet? 

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

Dana Hauser

  • 424 Points 250 badge 2x thumb
Our posts crossed there Chayce.  Yes, it's working great.  Now I just have to implement the User ID into my Invite button, which has to have the User ID.