Forum Discussion

ELANAMETH's avatar
ELANAMETH
Qrew Cadet
4 years ago

Using URLEncode Conditionally

Hello,
I have an API add record button that is passing through 4 different API calls. 
The first 3 are conditional (all, 1, or 2 can be called), and the 4th is always necessary. 
I realize that I need to use URLEncode for any of the clauses that are not first. I cannot default them all to begin with URLEncode, as the first clause cannot have that, but I can default #4 to use it, as it will never be first.
I tried having each variable end with it so that it, but that did not work.
Any other suggestions on how to use URLEncode conditionally?​

The individual variables work correctly, it's just the URLEncode for multiple calls that is messing things up.
var text urlAddApp = URLRoot() & "db/" & [_DBID_APPS] & "?a=API_AddRecord";

var text AP = $urlAddApp & //CREATE APPLICATION
                          "&_fid_6=" & URLEncode ([Related Company]) &
                          "&_fid_20=3" & //AP application
                          "&_fid_8=AWAITING APPLICATION FROM WEX" &
                          "&apptoken=xxxxxxxxxxxxxxxxxxxxxxxxxx";
                          
var text credit = $urlAddApp & //CREATE APPLICATION
                          "&_fid_6=" & URLEncode ([Related Company]) &
                          "&_fid_20=1" & //credit application
                          "&_fid_8=AWAITING APPLICATION FROM WEX" &
                          "&apptoken=xxxxxxxxxxxxxxxxxxxxxxxxxx";
                          
var text prefunded = $urlAddApp & //CREATE APPLICATION
                          "&_fid_6=" & URLEncode ([Related Company]) &
                          "&_fid_20=2" & //prefunded application
                          "&_fid_8=AWAITING APPLICATION FROM WEX" &
                          "&apptoken=xxxxxxxxxxxxxxxxxxxxxxxxxx";
                          
var text createNextActivity = URLEncode(URLRoot() & "db/" & Dbid() & "?a=API_AddRecord&_fid_18=" & URLEncode ([Related Company]) &
                              "&_fid_34=6" & 
                              "&_fid_6=" & Today() &
                              "&_fid_66=true" &
                              "&apptoken=xxxxxxxxxxxxxxxxxxxxxxxxxx" &
                              "&rdr=" & URLEncode(URLRoot() & "db/" & [_DBID_CO] & "?a=dr&rid=" & URLEncode ([Related Company])));
                              
                              


var text createAppAP = If(Contains([APPLICATION TYPE], "AP"), $AP & "&rdr=" );
var text createAppCredit = If(Contains([APPLICATION TYPE], "CORPORATE CREDIT"), $credit & "&rdr=");
var text createAppPrefunded = If(Contains([APPLICATION TYPE], "CORPORATE PREFUND"), $prefunded & "&rdr=");
                        
$createAppAP & $createAppcredit & $createAppprefunded & $createNextActivity​


------------------------------
E. P.
------------------------------

2 Replies

  • Here is a solution.  

    When I next URLs I always use this syntax.

    $URLONE
    & "&rdr=" & URLEncode($URLTWO)
    & URLEncode("&rdr=" & URLEncode($URLTHREE))
    & URLEncode(URLEncode("&rdr=" & URLEncode($URLFOUR)))

    It needs all four steps.

    The least worst options is to ensure that every one of the four steps does something even if it edits a dummy field to be blank based on a IF statement.  So then each of the four step will happens, it's just that some of the steps may be steps which will be a waste of an API call.  I don't think the planet will be significantly worse off than it already is with a wasted API call or three.  




    ------------------------------
    Mark Shnier (YQC)
    Quick Base Solution Provider
    Your Quick Base Coach
    http://QuickBaseCoach.com
    mark.shnier@gmail.com
    ------------------------------
    • ELANAMETH's avatar
      ELANAMETH
      Qrew Cadet
      Thank you!

      ------------------------------
      E. P.
      ------------------------------