Forum Discussion

EricEric3's avatar
EricEric3
Qrew Trainee
8 years ago

Page Refresh Challenge and Symptom

I have a two have formula field buttons with different yet similar functionality. 

The first one:
  • Clones an existing table record, with its related detail records, that a user is viewing/editing (Successfully)
  • Changes a field value on the new record (Successfully)
  • Refreshes the screen placing the user in the new record (Successfully)
var text Clone = URLRoot() &"db/"  & [_DBID_WIDGETS] & "?act=API_CopyMasterDetail&destRID=0" & "&sourcerid=" & [Record ID#] & "&copyfid=52" &  "&apptoken=######";

var text ValueUpdate = URLRoot() &"db/"  & [_DBID_WIDGETS] & "?act=API_EditRecord&rid=" & [Clone Record ID#] &  "&_fid_54=" & "False" & "&apptoken=######";

var text RefreshRecord=URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Clone Record ID#] & "&apptoken=######";

$Clone & "&rdr=" & URLEncode($ValueUpdate) & URLEncode("&rdr=" & URLEncode($RefreshRecord))

The second one:
  • Calls an Azure Cloud API that copies WIDGETS and DETAILS to another system (Successfully)
  • Changes a field value on the current record (makes a checkbox "true") (Successfuly)
  • Refreshes the screen placing the user again in the current record (Not Successfully)
var text AzureAPI = "http://#######.azurewebsites.net/api/########?db="; & [_DBID_WIDGET_DETAILS] & "&rid=" & [Record ID#];

var text Processed = URLRoot() &"db/"  &  [_DBID_WIDGETS] & "?act=API_EditRecord&rid=" & [Record ID#] &  "&_fid_60=" & "True" & "&apptoken=######";

var text RefreshRecord=URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID#] & "&apptoken=######";

$AzureAPI & "&rdr=" & URLEncode($Processed) & URLEncode("&rdr=" & URLEncode($RefreshRecord))

Unfortunately this doesn't refresh the page of the current record. It actually brings the user to the default List All screen of WIDGETS table.

I've tried a variation of the formula. Here is an example.

$AzureAPI & "&rdr=" & URLEncode($Processed) & URLEncode("&rdr=" & URLEncode("javascript:" & location.reload(true);" & "$.get('" & $RefreshRecord & "');" &"void(0);"))

But to no avail ... 

However if I remove the initial AzureAPI call ... the $RefreshRecord works as expected.

$Processed & "&rdr=" & URLEncode($RefreshRecord)

That is great but it defeats the purpose. Clearly when the AzureAPI URL call executes and then returns, it is throwing off the current page focus, and QuickBase is bouncing the user to the main WIGETS table default List ALL page.

Any help would be greatly appreciated.

6 Replies

  • The answer is very simple, the Azure API URL simply does not know what to do with the rdr parameter because it is not part of their API scheme so it ignores it.

    $AzureAPI & "&rdr=" & URLEncode($Processed) & URLEncode("&rdr=" & URLEncode($RefreshRecord))

    You can gain complete control of what happens after you make AJAX calls by doing everything in script rather than the formula language.
  • Ok I appreciate it ... So how would you re-code it based on your comments?

    The reason I ask is because I am not a javascript guy.
  • I am please asking for assistance in rewriting my code below in javascript per the recommendation made above. I haven't programmed in it and I really need a resolution to my problem. Your help would be greatly appreciate. 

    Thank you

    Formula field code that needs to be rewritten

    var text AzureAPI = "http://#######.azurewebsites.net/api/########?db="; & [_DBID_WIDGET_DETAILS] & "&rid=" & [Record ID#];

    var text Processed = URLRoot() &"db/"  &  [_DBID_WIDGETS] & "?act=API_EditRecord&rid=" & [Record ID#] &  "&_fid_60=" & "True" & "&apptoken=######";

    var text RefreshRecord=URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID#] & "&apptoken=######";

    $AzureAPI & "&rdr=" & URLEncode($Processed) & URLEncode("&rdr=" & URLEncode($RefreshRecord))
  • Typically writing script is beyond what developers offer for free on this forum. I suggest you contact Dan directly and engage him to do the work. I have used Dan in the past myself when non native coding is required.
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      Actually I frequently post scripts for unique solutions to forum questions and I am tending towards only posting to threads with script solutions. My priorities in answering questions generally involve promoting using script to solve novel problems or demonstrating that some seemingly "impossible" or "difficult" problem is in fact readily solvable with script.

      To be honest and not meaning to offend anyone, I can't keep up with the volume of daily messages since the move to the new forum software and in a lot of cases the person answering the question is putting way more effort into clarifying the issue than the original poster (this does not apply to your question - no offense intended). And a lot of times the original poster does not even include a question mark in their message - that makes no sense to me.

      But in any event, I think you need code similar to this:
      (function(){
        var dbid = "";
        var dbidWidgetDetails = "";
        var dbidWidgets = "";
        var apptoken = "";
        $.ajaxSetup({data: {apptoken: apptoken}});
        var urlAzureAPI = 'http://#######.azurewebsites.net/api/########?db=${dbidWidgetDetails}&rid=${kRid}';
        var urlProcessed = '${dbidWidgets}?act=API_EditRecord&rid=${kRid}&_fid_60=true';
        var urlRefreshRecord = '${dbidWidgets}?a=dr&rid=${kRid}';
        
        console.log(kRid);
        console.log(urlAzureAPI);
        console.log(urlProcessed);
        console.log(urlRefreshRecord);
        
        $.get(azureAPI)
          .then(function(response) {
            console.log(response);
            $.get(urlProcessed, function(xml) {
              console.log(xml);
              document.location = urlRefreshRecord;
            });
          });
      })();

      I didn't test it but you should be able to make progress by filling in the parameters {dbid, dbidWidgetDetails, dbidWidgets, apptoken, #######, #######} and pasting the script into the console and examining the debug statements.

      Beyond that advice, feel free to contact me off-world if you need individual assistance implementing this solution using the information in my profile:

      https://community.quickbase.com/people/dandiebolt
    • EricEric3's avatar
      EricEric3
      Qrew Trainee
      Very grateful for this Danimal. Thank you very much. I do have some questions so I will contact you directly off-world. Best Regards, Eric