Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result.ensureStatusNotFailure logic is incorrect #66

Open
jimmymcpeter opened this issue Jul 27, 2021 · 0 comments
Open

Result.ensureStatusNotFailure logic is incorrect #66

jimmymcpeter opened this issue Jul 27, 2021 · 0 comments

Comments

@jimmymcpeter
Copy link
Contributor

When you run executeBatch with the transaction attribute set to true,

//...
let requestConfig = new IA.RequestConfig();
requestConfig.transaction = true;
await intacctClient.executeBatch(apiFunctions, requestConfig);

I believe the initial thought with the following code calling ensureStatusNotFailure was that the offending function in the operation would be status=failure and any other proceeding functions status=aborted.

https://github.com/Intacct/intacct-sdk-js/blob/bdadac479a3ac6c8b2a34e5429b1ddf3afa740f1/src/Xml/Response/Result.ts#L186-L193

Unfortunately this isn't the case when the request's operation.transaction=true. All functions are returned with status=aborted and the offending function has a result.errors.length > 0. It looks like this is a similar problem on the other SDK's as well.

fixed-sample.js

let requestConfig = new IA.RequestConfig();
requestConfig.transaction = true;
const bufferResponse = await intacctClient.executeBatch(apiFunctions, requestConfig);
for (const result of bufferResponse.results) {
    if (result.status !== 'success' && result.errors.length > 0) {
        throw new ResultException(
            "Result status: " + result.status + " for Control ID: " + result.controlId,
            result.errors
        );
    }
}

Sample XML request for Postman

<?xml version="1.0" encoding="UTF-8"?>
<request>
  <control>
    <senderid>{{sender_id}}</senderid>
    <password>{{sender_password}}</password>
    <controlid>{{$timestamp}}</controlid>
    <uniqueid>false</uniqueid>
    <dtdversion>3.0</dtdversion>
    <includewhitespace>false</includewhitespace>
  </control>
  <operation transaction="true">
    <authentication>
      <sessionid>{{temp_session_id}}</sessionid>
    </authentication>
    <content>
      <function controlid="{{$guid}}">
        <create>
          <APBILL>
            <WHENCREATED>2021-07-27</WHENCREATED>
            <VENDORID>20000</VENDORID>
            <RECORDID>1234</RECORDID>
            <DOCNUMBER>Ref 5678</DOCNUMBER>
            <TERMNAME></TERMNAME>
            <WHENDUE>2021-08-27</WHENDUE>
            <CURRENCY>USD</CURRENCY>
            <BASECURR>USD</BASECURR>
            <EXCH_RATE_TYPE_ID>Intacct Daily Rate</EXCH_RATE_TYPE_ID>
            <ACTION>Draft</ACTION>
            <SUPDOCID>PMD-10251</SUPDOCID>
            <APBILLITEMS>
              <APBILLITEM>
                <ACCOUNTNO>6220</ACCOUNTNO>
                <TRX_AMOUNT>100.12</TRX_AMOUNT>
                <ENTRYDESCRIPTION>Line 1 of my bill</ENTRYDESCRIPTION>
                <VENDORID>20000</VENDORID>
              </APBILLITEM>
            </APBILLITEMS>
          </APBILL>
        </create>
      </function>
      
      <function controlid="{{$guid}}">
        <create_supdoc>
          <supdocid>PMD-10251</supdocid>
          <supdocname>Hello World</supdocname>
          <supdocfoldername></supdocfoldername>
          <supdocdescription>Description</supdocdescription>
          <attachments>
            <attachment>
              <attachmentname>My Attachment1</attachmentname>
              <attachmenttype>txt</attachmenttype>
              <attachmentdata>aGVsbG8gd29ybGQhIHRoaXMgaXMgYmFzZTY0IGVuY29kZWQgZGF0YQ==</attachmentdata>
            </attachment>
          </attachments>
        </create_supdoc>
      </function>

    </content>
  </operation>
</request>

Sample XML response

<?xml version="1.0" encoding="UTF-8"?>
<response>
    <control>
        <status>success</status>
        <senderid>xxxxxx</senderid>
        <controlid>1627412560</controlid>
        <uniqueid>false</uniqueid>
        <dtdversion>3.0</dtdversion>
    </control>
    <operation>
        <authentication>
            <status>success</status>
            <userid>xxx</userid>
            <companyid>xxxx</companyid>
            <locationid></locationid>
            <sessiontimestamp>2021-07-27T19:02:41+00:00</sessiontimestamp>
            <sessiontimeout>2021-07-28T01:02:41+00:00</sessiontimeout>
        </authentication>
        <result>
            <status>aborted</status>
            <function>create</function>
            <controlid>ec786abe-c541-4d42-92db-6cb2065baa68</controlid>
            <data listtype="objects" count="1">
                <apbill>
                    <RECORDNO>196</RECORDNO>
                </apbill>
            </data>
        </result>
        <result>
            <status>aborted</status>
            <function>create_supdoc</function>
            <controlid>490acf5e-0190-4277-a097-24ef64b5a26b</controlid>
            <errormessage>
                <error>
                    <errorno>BL03000113</errorno>
                    <description></description>
                    <description2>Folder name is not valid [Support ID: JDT2R%7EYQBYUWEsBPF3vEw6j8gTHQAAABo]</description2>
                    <correction></correction>
                </error>
                <error>
                    <errorno>XL03000009</errorno>
                    <description></description>
                    <description2>The entire transaction in this operation has been rolled back due to an error.</description2>
                    <correction></correction>
                </error>
            </errormessage>
        </result>
    </operation>
</response>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant