Forum Discussion

JasonJohnson's avatar
JasonJohnson
Qrew Assistant Captain
8 years ago

XML error after API commands executed in text formula button

I am receiving the following error when using a text-formula button -

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<qdbapi>
<action>API_AddRecord</action>
<errcode>0</errcode>
<errtext>No error</errtext>
<rid>167</rid>
<update_id>1499802606114</update_id>
</qdbapi>

The code is performing the edit and add record functions.

// Begin button style
var text bgcolor = "#4D2DD2";
var text txtcolor = "white";
var text style = "style=\"text-decoration: none;\n\n box-shadow: 3px 3px 1px #888888; \n\n background:" & $bgcolor & ";\n\n border-radius: 3px;\n\n padding: 5px 8px;\n\n color: " & $txtcolor & ";\n\n display: inline-block;\n\n font: bold 700 24px/1 \"Calibri\", sans-serif;\n\n text-align: center;\n\n text-shadow:none;";
// End button style

"<a " & $style & " href='" &URLRoot() & "/db/"& Dbid() & "?a=API_EditRecord&rid=" & [Record ID#] &
"&_fid_882=1" &
"&rdr=" &
URLEncode(URLRoot() & "db/" & [_DBID_Billing] & "?a=API_AddRecord&_fid_6=" & [Location ID])&
"&rdr="&
"javascript:" &
"',function(){" &
"location.reload(true);" &
"});"
& "void(0);"

&"'>CRAZY</a>
  • It's not firing your last RDR, you can only have one RDR I think but there may be another way or another param you can use but I don't know it. It would be much easier to just add IOL and handle this in a .js page. Much more control over your pages and easier to code.
  • JasonJohnson's avatar
    JasonJohnson
    Qrew Assistant Captain
    My js abilities are limited at best. I can go to a specified report using this -
    "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() &
    "?a=q&qid=1"))
    This would be acceptable but being able to place the button in a form or any report and return to the place that the button was used would be the favored outcome. I have attempted a few other codes but the issue is always the fact that I am making an edit and creating a new record in another table.
    • ChuckGrigsby's avatar
      ChuckGrigsby
      Qrew Cadet
      Feel free to contact me if you want help on how to implement this. Basically once IOL is there and you can load your javascript. You could perform multiple actions, edit multiple records or add many records with an ajax call then redirect to wherever you want. chuck@chuck.support and I can walk you through some of it if you like.
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      Xavier Fan posted some code on the old forum somewhere.  

      I have this code saved but not tested.

      var text URLOne = 

      URLRoot() & "db/" & [_DBID_TABLE_1]

      & "?act=api_editrecord&rid=" & ToText([Record ID#])

      & "&_fid_7=" & "1";

      var text URLTwo = 

      URLRoot() & "db/" & [_DBID_TABLE_1]

      & "?act=api_editrecord&rid=" & ToText([Record ID#])

      & "&_fid_8=" & "2";

      var text URLThree = "location.reload(true);";



      "javascript:" &

      "$.get('" & 

      $URLOne & 

      "').then(function(){" &

      "$.get('" &

      $URLTwo &

      "').then(function(){" &

      $URLThree & 

      "})" & 

      "});"

      & "void(0);
    • JasonJohnson's avatar
      JasonJohnson
      Qrew Assistant Captain
      I used that code and it failed to function at all.
  • This line:
    "',function(){" &
    has a single quote after the initial double quote - so you need to remove that, it's terminating your second rdr.
    ",function(){" &
    Also you'll need to add an apptoken (assuming your app requires them)
    • JasonJohnson's avatar
      JasonJohnson
      Qrew Assistant Captain
      Removing the single quote made no difference.
  • MCFNeil's avatar
    MCFNeil
    Qrew Captain
    You should be able to have multiple API calls in this.

    Maybe make the URL actions variables, or separate fields so you can be sure they aren't causing the issue. 
    Then bring them back together.

    It looks like just a syntax thing, so just break them out to individual pieces to troubleshoot. 
  • JasonJohnson's avatar
    JasonJohnson
    Qrew Assistant Captain
    We did go through several iterations and split it up to do more. The formula executes still but ends at the error so we are leaning toward the redirect and java being the issue since it is a zero error. Here is what we have at this point(minus the button style)

    var text URLOne = URLRoot() & "db/"& Dbid() & "?a=API_EditRecord&rid="& [Record ID#] &
    "&_fid_882=1";

    var text URLTwo = URLRoot() & "db/"& [_DBID_Billing]  & "?a=API_AddRecord" &
    "&_fid_6=" & [Location ID] &
    "&_fid_7=" & [Install Bill Amount] &
    "&_fid_8=" & [Project ID] &
    "&_fid_15=" & [Install Date] &
    "&_fid_17=" & URLEncode([Installation Description]) &
    "&_fid_19=" & [Type of Cancellation] &
    "&_fid_20=" & [Install Bill Amount] &
    "&_fid_22=" & [Address] &
    "&_fid_23=" & [City] &
    "&_fid_24=" & [State] &
    "&_fid_25=" & [Postal Code] &
    "&_fid_26=" & [County] &
    "&_fid_27=" & [Country] &
    "&_fid_28=" & [Related Project];

    var text URLThree = URLRoot() & "db/"& [_DBID_Billing]  & "?a=API_AddRecord" &
    "&_fid_6=" & [Location ID]&
    "&_fid_8=" & [Project ID]&
    "&_fid_15=" & [Install Date]&
    "&_fid_22=" & [Address]&
    "&_fid_23=" & [City]&
    "&_fid_24=" & [State]&
    "&_fid_25=" & [Postal Code]&
    "&_fid_28=" & [Related Project];

    "<a " & $style & " href='"
    & $URLOne
    & "&rdr=" & URLEncode($URLTwo)
    & URLEncode("&rdr=" & URLEncode($URLThree))
    & "javascript:"
    & ",function(){"
    & ".location.reload(true);"
    & "});"
    & "void(0);"

    &"'>The Button Issue</a>
  • The xml is saying no error but you are missing the reload, is that correct ? any way , this is my suggestion. 

    var text url1 = "[URL1]";
    var text url1 = "[URL2]";

    "javascript: "
    &"    $.get($URL1,function(xml1){"
    &"        if ( $(&quot;errcode&quot; , xml1).text() == &quot;0&quot;){"
    &"               $.get($URL2,function(xml2){"
    &"                    if ( $(&quot;errcode&quot; , xml2).text() == &quot;0&quot;){"
    &"                         location.reload(true);   "                       "    
    &"                    }else{ alert($(&quot;errtext&quot; , xml2).text() ) }"
    &"                })"
    &           }else{ alert($(&quot;errtext&quot; , xml1).text() ) }""
    &"    })"


    Keep in mind that you are writing three levels of encoding 
    " ' &quot; text &quot;' " 

    Hope this will help 

    Regards
    • JasonJohnson's avatar
      JasonJohnson
      Qrew Assistant Captain
      Yes it is missing the reload. I changed the section at the bottom to the below but I must be missing something because the button is now only firing off the first action not the second and still showing the zero error on the first action.

      "<a " & $style & " href='"
      &  "javascript: "
      &"    $.get($URLOne,function(xml1){"
      &"        if ( $(&quot;errcode&quot; , xml1).text() == &quot;0&quot;){"
      &"               $.get($URLTwo,function(xml2){"
      &"                    if ( $(&quot;errcode&quot; , xml2).text() == &quot;0&quot;){"
      &"                         location.reload(true);   "                      
      &"                     ;}else{ alert($(&quot;errtext&quot; , xml2).text() ) }"
      &"                })"
      &"           }else{ alert($(&quot;errtext&quot; , xml1).text() ) }"
      &"    })
  • JasonJohnson's avatar
    JasonJohnson
    Qrew Assistant Captain
    Here is a sample of the solution, thanks to Kirk Trachy!

    // Begin button style
    var text bgcolor = "#A5E294";
    var text txtcolor = "black";
    var text style = "style=\"text-decoration: none; box-shadow: 3px 3px 1px #888888; background:" & $bgcolor & "; border-radius: 3px; padding: 5px 8px; color: " & $txtcolor & "; display: inline-block; font: bold 700 24px/1 \" Calibri\", sans-serif; text-align: center; text-shadow:none;";
    // End button style


    var text URL= URLRoot() & "db/"& Dbid() & "?a=API_EditRecord&rid="& [Record ID#] &
    "&_fid_882=1"
    &"&rdr="
    &URLEncode(URLEncode(URLRoot() & "db/"& [_DBID_Billing]  & "?a=API_AddRecord" &
    "&_fid_6=" & [Location ID]&
    "&_fid_7=" & [Printer Bill Amount]&
    "&_fid_8=" & [Project ID]&
    "&_fid_9=" & [Install Date]&
    "&_fid_10=" & [Type of Cancellation]&
    "&_fid_11=" & [Install Bill Amount]&
    "&_fid_12=" & [PO Number]
    & "&rdr="
    & URLEncode( URLRoot() & "db/"& [_DBID_Billing]  & "?a=API_AddRecord" &
    "&_fid_6=" & [Location ID]&
    "&_fid_7=" & [Printer Bill Amount]&
    "&_fid_8=" & [Project ID]&
    "&_fid_9=" & [Install Date]&
    "&_fid_10=" & [Type of Cancellation]&
    "&_fid_11=" & [Install Bill Amount]&
    "&_fid_12=" & [PO Number]
    & "&rdr="
    & URLEncode( URLRoot() & "db/"& [_DBID_Billing]  & "?a=API_AddRecord" &
    "&_fid_6=" & [Location ID]&
    "&_fid_7=" & [Printer Bill Amount]&
    "&_fid_8=" & [Project ID]&
    "&_fid_9=" & [Install Date]&
    "&_fid_10=" & [Type of Cancellation]&
    "&_fid_11=" & [Install Bill Amount]&
    "&_fid_12=" & [PO Number]))));


    "<a " & $style & " href=\"javascript:" & "$.get('" & $URL & "', function(){" & "location.reload();" &
     "});" & "void(0);\">The Button Issue maybe</a>
  • .. or more simply now that we can color simply formula URL buttons

    define your separate URL's and then combine like this.




    $URLONE 
    & "&rdr=" & URLEncode($URLTWO)
    & URLEncode("&rdr=" & URLEncode($URLTHREE))
    & URLEncode(URLEncode("&rdr=" & URLEncode($URLFOUR)))
    & URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLFIVE))))
  • JasonJohnson's avatar
    JasonJohnson
    Qrew Assistant Captain
    Unfortunately Mark we are using buttons that change names, actions, colors, ability to place buttons anywhere the user wants without our QB team re-coding the buttons and give the end users that extra style that they want. Our business needs require all of this and URL buttons don't offer that. I did only put a rough code and at some point I could put a cleaner code if needed or you could contact me for a training session to help you understand this better.
  • Well maybe one day we will get button colorization formulas in the same way that we now have row colorization formulas.