How set value Rate for Items for new Estimate into my app

256 views Asked by At

I use QBFC v13 and Delphi XE6. The goal is to create Estimate and set its parameters into QuickBooks from my app.
I imported the type library from QBFC13 and added it to my project. My project was compiled without error. I created Estimate from my app (fragment 1, line: 04) and then I try set rate for its item. When I called function Rate.SetValue (fragment 1, line: 06), I had not had error message. Then I call DoRequest (fragment 1, line: 07) it all right. When I check StatusCode (fragment 1, line 09) it must be 0. But it is 3045, StatusMessage (fragment 1, line 10): "There was an error when converting the price '23.00' in the field 'item cost'. QuickBooks error message: This field contains an invalid character" .

Question #1: why it happened? (variable 'rate' is double and prototype SetValue(val: Double) has type of double).

Fragment 1:

01: var
02: rate: double;
    i: integer;
03:     rate := 23.00;
....
04:     estimateAdd := requestMsgSet.AppendEstimateAddRq();
....
05:     estimateLineAdd := estimateAdd.OREstimateLineAddList.Append.EstimateLineAdd;
....
06:     estimateLineAdd.ORRate.Rate.SetValue(rate);
....
07:     QueryResponse := SessionManager.DoRequests(requestMsgSet);
08:     i := response.StatusCode;
09:     if (i <> 0) then
10:         MessageDlg(response.StatusMessage, mtError, [mbOk], 0);

I found as partially resolved my problem. I can set value Rate make call Rate.SetAsString(const val: WideString) (fragment 2, line: 01) But appear other the problem. When variable rate has decimal part is zero all right, Estimate was added into QuickBooks. if decimal part is not zero (for example: rate := 23.10) I get exception in my app when called SetAsString procedure. and error message: "Invalid Price value".

Question #2: Why i can not rate with decimal part?

Fragment 2:

01:    estimateLineAdd.ORRate.Rate.SetAsString(FloatToStr(rate));

If I try to change parameter of procedure as string value: estimateLineAdd.ORRate.Rate.SetAsString('23.21') I have error as in first question. If I try to change parameter of procedure as: estimateLineAdd.ORRate.Rate.SetAsString('23,21') I get same exception and error message: "Invalid Price value." It is understandable, delimeter is '.' instead ','.


1

There are 1 answers

0
smg On

delimeter is '.' instead ','.

I have the same issue because QB was running on machine where , was used as separator, which is not supported: https://community.intuit.com/questions/1012431-how-to-change-number-formatting-decimal-and-grouping-separators

My regional settings in Windows are set to ru-RU locale, so QB shows prices as "60,12".

Seems like QBFC excepts .:

queryRq.ORSalesPurchase.SalesOrPurchase.ORPrice.Price.SetAsString("60,12"); // this immediatly throws
queryRq.ORSalesPurchase.SalesOrPurchase.ORPrice.Price.SetAsString("60.12"); // this is OK

When I do "get all Items" request, QB returns price with ,, (according to reginal settings):

<?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<ItemServiceQueryRs requestID="0" statusCode="0" statusSeverity="Info" statusMessage="Status OK">
<ItemServiceRet>
...
<SalesOrPurchase>
<Price>60,07</Price>

but obj.ORSalesPurchase.SalesOrPurchase.ORPrice.Price.GetValue(); returns 60 without any exception.

What is really strange, that (after I manually fix xml string returning from sendRequestXML) nor , neither . accepted my QuickBooks Pro 2017! In receiveResponseXML I got:

<ItemServiceAddRs requestID=\"0\" statusCode=\"3045\" statusSeverity=\"Error\" statusMessage=\"There was an error when converting the price &quot;60.12&quot; 
and
<ItemServiceAddRs requestID=\"0\" statusCode=\"3045\" statusSeverity=\"Error\" statusMessage=\"There was an error when converting the price &quot;60,12&quot;

After I change settings to en-US (for QB Pro US), all works with "60.12".