Discussions

 View Only
  • 1.  Query the Response from an API_AddRecord formula text button

    Posted 09-27-2017 13:46
    Hello,

    I have a formula text button which is an API_AddRecord and uses J-Growl notifcation to show the product has been added.  I made each product have a unique field so it can't be added twice.  The result is when the user clicks an already selected product it will still show the notification it has been added, but it will not add the product.  In the console I can see the reponseText showing the unique record error. 

    Overall the system works great but I was hoping to enhance it by showing a J-Growl notification that says the product has already been added based on the response.  Basically how do I query the API response and make the notification dynamic based on the response?  Below is my current code within my formula text button.  The $ADDPROD variable is a simple API_AddRecord.  Let me know if this is possible within the formula-text field or if I have to create a code page for it.

    var text URL = 
    "javascript:" &
    "console.log($.get('" & 
    $ADDPROD & 
    "',function(){" &
    "$.jGrowl('"&[Product Name]&" Added', {life: 5000, theme: 'jGrowl-green'});" &
    "}));" &
    "void(0);";   

    "<a href=\"" & $URL &"\"" & ">Add to Activity" &  "</a>"

    Thanks!


  • 2.  RE: Query the Response from an API_AddRecord formula text button

    Posted 09-27-2017 13:59
    First I wouldn't use the $.get inside console.log. I'd be willing to give you a hand if you're willing to do this in a .js custom page instead of a formula text .and then adding an invisible field to load the JS file known as the image onload technique. It's a pretty simple setup and can be found on the forum. If you add IOL and want help feel free to reach out. Chuck@Chuck.Support


  • 3.  RE: Query the Response from an API_AddRecord formula text button

    Posted 09-27-2017 15:09
    Great.  The only reason I used console.log was to see what it looked like but that was as far as I got.  It sounds like I will absolutely need a code page.  I am pretty sure I have the resources to make the code page. 

    My question is why use IOL can't I just use an a href tag and link to said code page?  Love the IOL technique, we use it all over the place, just trying to understand it better. 

    Thanks!


  • 4.  RE: Query the Response from an API_AddRecord formula text button

    Posted 09-27-2017 15:13
    I'll let Dan answer since it's his technique but that's essentially what you're doing. You're creating an img field with that file as the source. His technique for using the global variables just make it easier to scale if you add more code pages later. So instead of having to copy all the img html code each time you just have [iol]& "yourcode.js" & [/iol]. Less is best in coding


  • 5.  RE: Query the Response from an API_AddRecord formula text button

    Posted 09-27-2017 15:33
    In this particular use case you could forgo using the IOL technique and just call $.getScript() through one of these mechanisms when the link was clicked by the user:

    <a href=javascript:$.getScript(...)>Click Me</a>

    <a onclick=$.getScript(...)>Click Me</a>

    Using the IOL technique is essential when you want to immediately call the script in your code page rather than wait for some user interactions such as clicking on a link.

    But the point in favor of always using IOL is why craft a bunch of different solutions over the lifetime of you applicatioin when you can simply set up IOL once and uniformly invoke it through the standard method whenever needed:

    [iol] & "moduleTable.js" & [/iol]

    Why litter your brain remembering a dozen different partial solutions?


  • 6.  RE: Query the Response from an API_AddRecord formula text button

    Posted 09-27-2017 14:56
    You have to use script to process the response of an API method. Chuck is a Certified Image Onload QuickBase DeveloperTM so you are in good hands. We have other QuickBase certificfation programs available you may be interested in when you have more ambitious scripting requirements::
    • Certified Image Onload QuickBase Developer&trade;
    • Certified Branding Onload QuickBase DeveloperTM
    • Certified Service Worker QuickBase DeveloperTM
    • Certified Async/Await QuickBase DeveloperTM
    • Certified Observables QuickBase DeveloperTM


  • 7.  RE: Query the Response from an API_AddRecord formula text button

    Posted 09-27-2017 14:59
    Woot! Excited to try async/await