Discussions

Expand all | Collapse all

XML error after API commands executed in text formula button

  • 1.  XML error after API commands executed in text formula button

    Posted 07-11-2017 19:54
    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>


  • 2.  RE: XML error after API commands executed in text formula button

    Bronze
    Contributor
    Posted 07-11-2017 20:04
    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.


  • 3.  RE: XML error after API commands executed in text formula button

    Posted 07-11-2017 20:37
    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.


  • 4.  RE: XML error after API commands executed in text formula button

    Bronze
    Contributor
    Posted 07-11-2017 20:47
    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.


  • 5.  RE: XML error after API commands executed in text formula button

    Posted 07-11-2017 20:51
    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);


  • 6.  RE: XML error after API commands executed in text formula button

    Posted 07-11-2017 20:53
    I used that code and it failed to function at all.


  • 7.  RE: XML error after API commands executed in text formula button

    Bronze
    Contributor
    Posted 07-11-2017 20:59
    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();
                    })
                });


  • 8.  RE: XML error after API commands executed in text formula button

    Posted 07-11-2017 20:46
    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)


  • 9.  RE: XML error after API commands executed in text formula button

    Posted 07-11-2017 20:55
    Removing the single quote made no difference.


  • 10.  RE: XML error after API commands executed in text formula button

    Top
    Contributor
    Posted 07-13-2017 06:27
    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. 


  • 11.  RE: XML error after API commands executed in text formula button

    Posted 07-13-2017 11:40
    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>


  • 12.  RE: XML error after API commands executed in text formula button

    Posted 07-18-2017 20:00
    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


  • 13.  RE: XML error after API commands executed in text formula button

    Posted 07-18-2017 20:26
    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() ) }"
    &"    })


  • 14.  RE: XML error after API commands executed in text formula button

    Posted 08-16-2017 17:07
    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>


  • 15.  RE: XML error after API commands executed in text formula button

    Posted 08-16-2017 17:21
    .. 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))))


  • 16.  RE: XML error after API commands executed in text formula button

    Posted 08-17-2017 12:01
    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.


  • 17.  RE: XML error after API commands executed in text formula button

    Posted 08-17-2017 13:45
    Well maybe one day we will get button colorization formulas in the same way that we now have row colorization formulas.