XML error after API commands executed in text formula button

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered
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>"
Photo of Jason

Jason

  • 1,012 Points 1k badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of Chuck Grigsby

Chuck Grigsby

  • 1,978 Points 1k badge 2x thumb
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.
Photo of Jason

Jason

  • 1,012 Points 1k badge 2x thumb
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.
Photo of Chuck Grigsby

Chuck Grigsby

  • 1,958 Points 1k badge 2x thumb
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.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 49,430 Points 20k badge 2x thumb
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);"
Photo of Jason

Jason

  • 1,012 Points 1k badge 2x thumb
I used that code and it failed to function at all.
Photo of Chuck Grigsby

Chuck Grigsby

  • 1,958 Points 1k badge 2x thumb
Here's an example of what the code would look like. for a get it would just be $.get(dbid, {act:"API_EditRecord", rid: kRid, _fid_123:"Some Value"}, callback)

$('#qbu_approvePurchaseBtn').on('click',
            function() {
                $.post(dbidNotes, {
                    act: "API_AddRecord",
                    _fid_10: kRid,
                    _fid_9: "Purchase Approved"
                }, function(resp) {
                    console.dirxml(resp)
                    $('#saveButton').click();
                })
            });
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)
Photo of Jason

Jason

  • 1,012 Points 1k badge 2x thumb
Removing the single quote made no difference.
Photo of Matthew Neil

Matthew Neil

  • 31,438 Points 20k badge 2x thumb
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. 
Photo of Jason

Jason

  • 1,012 Points 1k badge 2x thumb
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>"
Photo of Ammar

Ammar

  • 312 Points 250 badge 2x thumb
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
Photo of Jason

Jason

  • 1,012 Points 1k badge 2x thumb
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() ) }"
&"    })"
Photo of Jason

Jason

  • 1,012 Points 1k badge 2x thumb
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>"
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,296 Points 50k badge 2x thumb
.. 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))))
(Edited)
Photo of Jason

Jason

  • 1,012 Points 1k badge 2x thumb
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.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,296 Points 50k badge 2x thumb
Well maybe one day we will get button colorization formulas in the same way that we now have row colorization formulas.