DataExtDefAdd(2.0)

This request adds a data extension definition to the specified object type (e.g. Customer) so that extension data can be written to a particular object of that type (e.g., this customer, John Smith. A data extension definition must be created before data can be written to the data extension.
Notice that a custom field data extension definition can be created either by using DataExtDefAdd or via the QuickBooks UI by the user specifying a custom field for an object. Only custom fields can be defined through the UI, however, not private data extensions.
Via the SDK, you create a custom field definition by setting the OwnerID to 0. You create a private data definition by setting OwnerID to a GUID that only your application owns or shares with other applications. Custom fields are available and visible within the QuickBooks UI, whereas private data extensions are seen and used only by your own application or other applications that know the OwnerID GUID.
Data is written to custom fields either via the SDK DataExtAdd/Mod requests or via the QuickBooks UI directly by the end user. Data is written to private data extensions only via the SDK DataExtAdd/Mod requests. You should be careful not to use private data extensions in transaction line items because queries will not return that private data (use only custom fields on transaction line items).
Notice that creating a custom field data extension definition for Customer and Item causes an automatic propagation of that definition to certain transaction objects. See “AssignToObject” for more details. A full description of this behavior and its usefulness is provided in the QB SDK Programmer’s Guide. DataExtDefAdd does not cause any events to be generated.

Request

Response

XMLOps

VB.NET

C#

Tag Type Max length Implementation Required

IDataExtDefAdd

This request adds a data extension definition to the specified object type (e.g. Customer) so that extension data can be written to a particular object of that type (e.g., this customer, John Smith. A data extension definition must be created before data can be written to the data extension. Notice that a custom field data extension definition can be created either by using DataExtDefAdd or via the QuickBooks UI by the user specifying a custom field for an object. Only custom fields can be defined through the UI, however, not private data extensions. Via the SDK, you create a custom field definition by setting the OwnerID to 0. You create a private data definition by setting OwnerID to a GUID that only your application owns or shares with other applications. Custom fields are available and visible within the QuickBooks UI, whereas private data extensions are seen and used only by your own application or other applications that know the OwnerID GUID. Data is written to custom fields either via the SDK DataExtAdd/Mod requests or via the QuickBooks UI directly by the end user. Data is written to private data extensions only via the SDK DataExtAdd/Mod requests. You should be careful not to use private data extensions in transaction line items because queries will not return that private data (use only custom fields on transaction line items). Notice that creating a custom field data extension definition for Customer and Item causes an automatic propagation of that definition to certain transaction objects. See “AssignToObject” for more details. A full description of this behavior and its usefulness is provided in the QB SDK Programmer’s Guide (PDF, 9.6 MB). DataExtDefAdd does not cause any events to be generated.
    2.0  

OwnerID

OwnerID refers to the owner of a data extension. A value of 0 means the data extension is a custom field visible and usable within the QuickBooks UI. Any other non zero value that is a valid GUID means that the data extension is a private data extension. Usually you would keep your application’s GUID confidential to prevent other applications from accessing your data extensions. But if you want to share data extensions with another application, the applications need to use the same GUID. In this case, each application could use two GUIDs, one for shared data extensions and one for confidential data extensions. (An application can have any number of GUIDs.) When you share a data extension with another application, the other application must know both the OwnerID and the DataExtName, as these together form a data extension’s unique name.
IQBGUIDType     Y

DataExtName

The name of the data extension. If this is a custom field, DataExtName will be visible as a label in the QuickBooks user interface. Also because OwnerID and DataExtName together make the data extension unique, and because custom fields all have the same OwnerID of zero, the DataExtName must be a unique value among existing custom fields. In contrast, the DataExtName for private data extensions must be unique only for the specified OwnerID GUID.
IQBStringType 31 chars   Y

DataExtType

The field’s data type, which corresponds to a qbXML data type. In an IDataExtDefAdd request object, if this is a custom field, DataExtType must be detSTR255TYPE.
IQBENDataExtTypeType     Y

AssignToObjectList

A list of AssignToObject enum values. If this is a private data extension definition (the OwnerID value is a non-zero GUID), then AssignToObject is optional and any of the enumerated objects listed below can be specified for AssignToObject. If this is a custom field definition (the OwnerID value is 0), then AssignToObject is required. If this data ext definition is for a custom field, then only Customer, Employee, Vendor, or Item can be specified in AssignToObject. Notice that assigning to Customer or Item results in automatic propagation (assigning) to the following objects, where the custom field is available at the transaction level or transaction line item level: CreditMemo Estimate Invoice PurchaseOrder (only if AssigntoObject is set to Item) SalesOrderSalesReceipt
IENAssignToObjectList      

DataExtListRequire

If DataExtListRequire is true, this data extension field is required to be entered in lists. The default value is false.
IQBBoolType   12.0  

DataExtTxnRequire

If DataExtTxnRequire is true, this data extension field is required to be entered in transaction. The default value is false.
IQBBoolType   12.0  

DataExtFormatString

The string format required for the data extension.
IQBStringType   12.0  

IncludeRetElementList

You use this if you want to limit the data that will be returned in the response. In this list, you specify the name of each top-level element or aggregate that you want to be returned in the response to the request. You cannot specify fields within an aggregate, for example, you cannot specify a City within an Address: you must specify Address and will get the entire address. The names specified in the list are not parsed, so you must be especially careful to supply valid names, properly cased. No error is returned in the status code if you specify an invalid name. Notice that if you want to return custom data or private data extensions, you must specify the DataExtRet element and you must supply the OwnerID set to either a value of 0 (custom data) or the GUID for the private data.
IBSTRList 50 chars 4.0  
Tag Type Max length Implementation Required

IResponse

This request adds a data extension definition to the specified object type (e.g. Customer) so that extension data can be written to a particular object of that type (e.g., this customer, John Smith. A data extension definition must be created before data can be written to the data extension. Notice that a custom field data extension definition can be created either by using DataExtDefAdd or via the QuickBooks UI by the user specifying a custom field for an object. Only custom fields can be defined through the UI, however, not private data extensions. Via the SDK, you create a custom field definition by setting the OwnerID to 0. You create a private data definition by setting OwnerID to a GUID that only your application owns or shares with other applications. Custom fields are available and visible within the QuickBooks UI, whereas private data extensions are seen and used only by your own application or other applications that know the OwnerID GUID. Data is written to custom fields either via the SDK DataExtAdd/Mod requests or via the QuickBooks UI directly by the end user. Data is written to private data extensions only via the SDK DataExtAdd/Mod requests. You should be careful not to use private data extensions in transaction line items because queries will not return that private data (use only custom fields on transaction line items). Notice that creating a custom field data extension definition for Customer and Item causes an automatic propagation of that definition to certain transaction objects. See “AssignToObject” for more details. A full description of this behavior and its usefulness is provided in the QB SDK Programmer’s Guide (PDF, 9.6 MB). DataExtDefAdd does not cause any events to be generated.
    2.0  

StatusCode

A number that corresponds to a statusSeverity and statusMessage. Five status codes relate directly to signon messages: 2000, 2010, 2020, 2030, and 2040. For details about these and other statusCode values that can be returned, see the statusCode table on the Error Codes page.
IQBIntType     Y

StatusSeverity

One of the following values: INFO The request was completed, and the results are consistent with what your application expected. WARNING The request was completed, but the results might not be consistent with what you expected. ERROR The request was not completed. No data will appear in the server’s response after the statusMessage.
IQBStringType     Y

StatusMessage

A user-readable explanation of the success or error condition that is indicated by the statusCode. For details about the statusMessage values that can be returned, see the “Explanation” column of the statusCode table on the Error Codes page.
IQBStringType     Y

Detail

IDataExtDefRet      

OwnerID

OwnerID refers to the owner of a data extension. A value of 0 means the data extension is a custom field visible and usable within the QuickBooks UI. Any other non zero value that is a valid GUID means that the data extension is a private data extension. Usually you would keep your application’s GUID confidential to prevent other applications from accessing your data extensions. But if you want to share data extensions with another application, the applications need to use the same GUID. In this case, each application could use two GUIDs, one for shared data extensions and one for confidential data extensions. (An application can have any number of GUIDs.) When you share a data extension with another application, the other application must know both the OwnerID and the DataExtName, as these together form a data extension’s unique name.
IQBGUIDType      

DataExtID

The ID of the data extension.
IQBIntType   11.0 Y

DataExtName

The name of the data extension. If this is a custom field, DataExtName will be visible as a label in the QuickBooks user interface. Also because OwnerID and DataExtName together make the data extension unique, and because custom fields all have the same OwnerID of zero, the DataExtName must be a unique value among existing custom fields. In contrast, the DataExtName for private data extensions must be unique only for the specified OwnerID GUID.
IQBStringType 31 chars   Y

DataExtType

The field’s data type, which corresponds to a qbXML data type. In an IDataExtDefAdd request object, if this is a custom field, DataExtType must be detSTR255TYPE.
IQBENDataExtTypeType     Y

AssignToObjectList

A list of AssignToObject enum values. If this is a private data extension definition (the OwnerID value is a non-zero GUID), then AssignToObject is optional and any of the enumerated objects listed below can be specified for AssignToObject. If this is a custom field definition (the OwnerID value is 0), then AssignToObject is required. If this data ext definition is for a custom field, then only Customer, Employee, Vendor, or Item can be specified in AssignToObject. Notice that assigning to Customer or Item results in automatic propagation (assigning) to the following objects, where the custom field is available at the transaction level or transaction line item level: CreditMemo Estimate Invoice PurchaseOrder (only if AssigntoObject is set to Item) SalesOrderSalesReceipt
IENAssignToObjectList      

DataExtListRequire

If DataExtListRequire is true, this data extension field is required to be entered in lists. The default value is false.
IQBBoolType   11.0 Y

DataExtTxnRequire

If DataExtTxnRequire is true, this data extension field is required to be entered in transaction. The default value is false.
IQBBoolType   11.0 Y

DataExtFormatString

The string format required for the data extension.
IQBStringType   11.0 Y

Detail

IErrorRecovery   11.0  

ORListOwnerTxn

IORListOwnerTxn     Y

ListID

Along with FullName, ListID is a way to identify a list object. When a list object is added to QuickBooks through the SDK or through the QuickBooks user interface, the server assigns it a ListID. A ListID is not unique across lists, but it is unique across each particular type of list. For example, two customers could not have the same ListID, and a customer could not have the same ListID as an employee (because Customer and Employee are both name lists). But a customer could have the same ListID as a non-inventory item.
IQBIDType      

OwnerID

Refers to the owner of a data extension:If OwnerID is 0, this is a public data extension, also known as a custom field. Custom fields appear in the QuickBooks UI.If OwnerID is a GUID, for example {6B063959-81B0-4622-85D6-F548C8CCB517}, this field is a private data extension defined by an integrated application. Private data extensions do not appear in the QuickBooks UI. Note that OwnerID values are not case-sensitive, meaning that if you enter an OwnerID value with lower-case letters, the value will be saved and returned with upper-case letters. When you share a private data extension with another application, the other application must know both the OwnerID and the DataExtName, as these together form a data extension’s unique name.
IQBGUIDType      

TxnID

QuickBooks generates a unique TxnID for each transaction that is added to QuickBooks. A TxnID returned from a request can be used to refer to the transaction in subsequent requests. Notice that you cannot supply the TxnID of a TimeTracking transaction to TransactionQueryRq requests. If you do, you get an error stating that no such record could be found, even though the transaction is in QuickBooks. This behavior reflects the behavior in the QuicKBooks UI in the Find window.
IQBIDType      

TxnNumber

An identifying number for this transaction.
IQBIntType      

EditSequence

A number that the server generates and assigns to this object. Every time the object is changed, the server will change its EditSequence value. When you try to modify a list object, you must provide its EditSequence. The server compares the EditSequence you provide with the EditSequence in memory to make sure you are dealing with the latest copy of the object. If you are not, the server will reject the request and return an error. Because EditSequence is only used to check whether two objects match, there is no reason to interpret its value.
IQBStringType 16 chars    

ExternalGUID

Allows for the attachment of a user defined GUID value.
IQBGUIDType      

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="16.0"?>
<QBXML>
        <QBXMLMsgsRq onError="stopOnError">
                <DataExtDefAddRq>
                        <DataExtDefAdd> <!-- required -->
                                <OwnerID >GUIDTYPE</OwnerID> <!-- required -->
                                <DataExtName >STRTYPE</DataExtName> <!-- required -->
                                <!-- DataExtType may have one of the following values: AMTTYPE, DATETIMETYPE, INTTYPE, PERCENTTYPE, PRICETYPE, QUANTYPE, STR1024TYPE, STR255TYPE -->
                                <DataExtType >ENUMTYPE</DataExtType> <!-- required -->
                                <!-- AssignToObject may have one of the following values: Account, ARRefundCreditCard, Bill, BillPaymentCheck, BillPaymentCreditCard, BuildAssembly, Charge, Check, Company, CreditCardCharge, CreditCardCredit, CreditMemo, Customer, Deposit, Employee, Estimate, InventoryAdjustment, Invoice, Item, ItemReceipt, JournalEntry, OtherName, PurchaseOrder, ReceivePayment, SalesOrder, SalesReceipt, SalesTaxPaymentCheck, Vendor, VendorCredit -->
                                <AssignToObject >ENUMTYPE</AssignToObject> <!-- optional, may repeat -->
                                <DataExtListRequire >BOOLTYPE</DataExtListRequire> <!-- optional -->
                                <DataExtTxnRequire >BOOLTYPE</DataExtTxnRequire> <!-- optional -->
                                <DataExtFormatString >STRTYPE</DataExtFormatString> <!-- optional -->
                        </DataExtDefAdd>
                        <IncludeRetElement >STRTYPE</IncludeRetElement> <!-- optional, may repeat -->
                </DataExtDefAddRq>

                <DataExtDefAddRs statusCode="INTTYPE" statusSeverity="STRTYPE" statusMessage="STRTYPE">
                        <DataExtDefRet> <!-- optional -->
                                <OwnerID >GUIDTYPE</OwnerID> <!-- optional -->
                                <DataExtID >INTTYPE</DataExtID> <!-- required -->
                                <DataExtName >STRTYPE</DataExtName> <!-- required -->
                                <!-- DataExtType may have one of the following values: AMTTYPE, DATETIMETYPE, INTTYPE, PERCENTTYPE, PRICETYPE, QUANTYPE, STR1024TYPE, STR255TYPE -->
                                <DataExtType >ENUMTYPE</DataExtType> <!-- required -->
                                <!-- AssignToObject may have one of the following values: Account, ARRefundCreditCard, Bill, BillPaymentCheck, BillPaymentCreditCard, BuildAssembly, Charge, Check, Company, CreditCardCharge, CreditCardCredit, CreditMemo, Customer, Deposit, Employee, Estimate, InventoryAdjustment, Invoice, Item, ItemReceipt, JournalEntry, OtherName, PurchaseOrder, ReceivePayment, SalesOrder, SalesReceipt, SalesTaxPaymentCheck, Vendor, VendorCredit -->
                                <AssignToObject >ENUMTYPE</AssignToObject> <!-- optional, may repeat -->
                                <DataExtListRequire >BOOLTYPE</DataExtListRequire> <!-- required -->
                                <DataExtTxnRequire >BOOLTYPE</DataExtTxnRequire> <!-- required -->
                                <DataExtFormatString >STRTYPE</DataExtFormatString> <!-- required -->
                        </DataExtDefRet>
                        <ErrorRecovery> <!-- optional -->
                                <!-- BEGIN OR -->
                                        <ListID >IDTYPE</ListID> <!-- optional -->
                                <!-- OR -->
                                        <OwnerID >GUIDTYPE</OwnerID> <!-- optional -->
                                <!-- OR -->
                                        <TxnID >IDTYPE</TxnID> <!-- optional -->
                                <!-- END OR -->
                                <TxnNumber >INTTYPE</TxnNumber> <!-- optional -->
                                <EditSequence >STRTYPE</EditSequence> <!-- optional -->
                                <ExternalGUID >GUIDTYPE</ExternalGUID> <!-- optional -->
                        </ErrorRecovery>
                </DataExtDefAddRs>
        </QBXMLMsgsRq>
</QBXML>

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
'The following sample code is generated as an illustration of
'Creating requests and parsing responses ONLY
'This code is NOT intended to show best practices or ideal code
'Use at your most careful discretion

imports System
imports System.Net
imports System.Drawing
imports System.Collections
imports System.ComponentModel
imports System.Windows.Forms
imports System.Data
imports System.IO
imports Interop.QBFC16

Module com.intuit.idn.samples
        Public Class Sample
                Public Sub  DoDataExtDefAdd()
                        Dim sessionBegun as Boolean
                        sessionBegun = False
                        Dim connectionOpen as Boolean
                        connectionOpen = False
                        Dim sessionManager as QBSessionManager
                        sessionManager = nothing

                        Try
                                'Create the session Manager object
                                sessionManager = new QBSessionManager

                                'Create the message set request object to hold our request
                                Dim requestMsgSet as IMsgSetRequest
                                requestMsgSet = sessionManager.CreateMsgSetRequest("US",16,0)
                                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue

                                BuildDataExtDefAddRq(requestMsgSet)

                                'Connect to QuickBooks and begin a session
                                sessionManager.OpenConnection("","Sample Code from OSR")
                                connectionOpen = True
                                sessionManager.BeginSession("", ENOpenMode.omDontCare)
                                sessionBegun = True

                                'Send the request and get the response from QuickBooks
                                Dim responseMsgSet as IMsgSetResponse
                                responseMsgSet = sessionManager.DoRequests(requestMsgSet)

                                'End the session and close the connection to QuickBooks
                                sessionManager.EndSession()
                                sessionBegun = False
                                sessionManager.CloseConnection()
                                connectionOpen = False

                                WalkDataExtDefAddRs(responseMsgSet)
                        Catch e as Exception
                                MessageBox.Show(e.Message, "Error")
                                if (sessionBegun) then
                                        sessionManager.EndSession()
                                End If
                                if (connectionOpen) then
                                        sessionManager.CloseConnection()
                                End If
                        End Try
                End Sub
                Public Sub BuildDataExtDefAddRq(requestMsgSet as IMsgSetRequest)
                        Dim DataExtDefAddRq as IDataExtDefAdd
                        DataExtDefAddRq= requestMsgSet.AppendDataExtDefAddRq()
                        'Set field value for OwnerID
                        DataExtDefAddRq.OwnerID.SetValue(System.Guid.NewGuid().ToString())
                        'Set field value for DataExtName
                        DataExtDefAddRq.DataExtName.SetValue("ab")
                        'Set field value for DataExtType
                        DataExtDefAddRq.DataExtType.SetValue(ENDataExtType.detAMTTYPE)
                        'Set field value for AssignToObjectList
                        'May create more than one of these if needed
                        DataExtDefAddRq.AssignToObjectList.Add(ENAssignToObjectList.atolAccount)
                        'Set field value for DataExtListRequire
                        DataExtDefAddRq.DataExtListRequire.SetValue(True)
                        'Set field value for DataExtTxnRequire
                        DataExtDefAddRq.DataExtTxnRequire.SetValue(True)
                        'Set field value for DataExtFormatString
                        DataExtDefAddRq.DataExtFormatString.SetValue("ab")
                        'Set field value for IncludeRetElementList
                        'May create more than one of these if needed
                        DataExtDefAddRq.IncludeRetElementList.Add("ab")
                End Sub




                Public Sub WalkDataExtDefAddRs( responseMsgSet as IMsgSetResponse)
                        if (responseMsgSet is nothing) then
                                Exit Sub
                        End If

                        Dim responseList as IResponseList
                        responseList = responseMsgSet.ResponseList
                        if (responseList is nothing) then
                                Exit Sub
                        End If

                        'if we sent only one request, there is only one response, we'll walk the list for this sample
                        for j=0 to responseList.Count-1
                                Dim response as IResponse
                                response = responseList.GetAt(j)
                                'check the status code of the response, 0=ok, >0 is warning
                                if (response.StatusCode >= 0) then
                                        'the request-specific response is in the details, make sure we have some
                                        if (not response.Detail is nothing) then
                                                'make sure the response is the type we're expecting
                                                Dim responseType as ENResponseType
                                                responseType = CType(response.Type.GetValue(),ENResponseType)
                                                if (responseType == ENResponseType.rtDataExtDefAddRs) then
                                                        'upcast to more specific type here, this is safe because we checked with response.Type check above
                                                        Dim DataExtDefRet as IDataExtDefRet
                                                        DataExtDefRet = CType(response.Detail,IDataExtDefRet)
                                                        WalkDataExtDefRet(DataExtDefRet)
                                                End If
                                        End If
                                End If
                        Next j
                End Sub




                Public Sub WalkDataExtDefRet(DataExtDefRet as IDataExtDefRet)
                        if (DataExtDefRet is nothing) then
                                Exit Sub
                        End If

                        'Go through all the elements of IDataExtDefRet
                        'Get value of OwnerID
                        if ( not DataExtDefRet.OwnerID is nothing) then
                                Dim OwnerID7833 as String
                                OwnerID7833 = DataExtDefRet.OwnerID.GetValue()
                        End If
                        'Get value of DataExtID
                        Dim DataExtID7834 as Integer
                        DataExtID7834 = DataExtDefRet.DataExtID.GetValue()
                        'Get value of DataExtName
                        Dim DataExtName7835 as String
                        DataExtName7835 = DataExtDefRet.DataExtName.GetValue()
                        'Get value of DataExtType
                        Dim DataExtType7836 as ENDataExtType
                        DataExtType7836 = DataExtDefRet.DataExtType.GetValue()
                        'Get value of AssignToObjectList
                        if ( not DataExtDefRet.AssignToObjectList is nothing) then
                                Dim AssignToObject7837 as ENAssignToObjectList
                                AssignToObject7837 = DataExtDefRet.AssignToObjectList.GetValue()
                        End If
                        'Get value of DataExtListRequire
                        Dim DataExtListRequire7838 as Boolean
                        DataExtListRequire7838 = DataExtDefRet.DataExtListRequire.GetValue()
                        'Get value of DataExtTxnRequire
                        Dim DataExtTxnRequire7839 as Boolean
                        DataExtTxnRequire7839 = DataExtDefRet.DataExtTxnRequire.GetValue()
                        'Get value of DataExtFormatString
                        Dim DataExtFormatString7840 as String
                        DataExtFormatString7840 = DataExtDefRet.DataExtFormatString.GetValue()
                End Sub




        End Class
End Module

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//The following sample code is generated as an illustration of
//Creating requests and parsing responses ONLY
//This code is NOT intended to show best practices or ideal code
//Use at your most careful discretion

using System;
using System.Net;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Interop.QBFC16;

namespace com.intuit.idn.samples
{
        public class Sample
        {
                public void  DoDataExtDefAdd()
                {
                        bool sessionBegun = false;
                        bool connectionOpen = false;
                        QBSessionManager sessionManager = null;

                        try
                        {
                                //Create the session Manager object
                                sessionManager = new QBSessionManager();

                                //Create the message set request object to hold our request
                                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US",16,0);
                                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                                BuildDataExtDefAddRq(requestMsgSet);

                                //Connect to QuickBooks and begin a session
                                sessionManager.OpenConnection("","Sample Code from OSR");
                                connectionOpen = true;
                                sessionManager.BeginSession("", ENOpenMode.omDontCare);
                                sessionBegun = true;

                                //Send the request and get the response from QuickBooks
                                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);

                                //End the session and close the connection to QuickBooks
                                sessionManager.EndSession();
                                sessionBegun = false;
                                sessionManager.CloseConnection();
                                connectionOpen = false;

                                WalkDataExtDefAddRs(responseMsgSet);
                        }
                        catch (Exception e)
                        {
                                MessageBox.Show(e.Message, "Error");
                                if (sessionBegun)
                                {
                                        sessionManager.EndSession();
                                }
                                if (connectionOpen)
                                {
                                        sessionManager.CloseConnection();
                                }
                        }
                }
                void BuildDataExtDefAddRq(IMsgSetRequest requestMsgSet)
                {
                        IDataExtDefAdd DataExtDefAddRq= requestMsgSet.AppendDataExtDefAddRq();
                        //Set field value for OwnerID
                        DataExtDefAddRq.OwnerID.SetValue(Guid.NewGuid().ToString());
                        //Set field value for DataExtName
                        DataExtDefAddRq.DataExtName.SetValue("ab");
                        //Set field value for DataExtType
                        DataExtDefAddRq.DataExtType.SetValue(ENDataExtType.detAMTTYPE);
                        //Set field value for AssignToObjectList
                        //May create more than one of these if needed
                        DataExtDefAddRq.AssignToObjectList.Add(ENAssignToObjectList.atolAccount);
                        //Set field value for DataExtListRequire
                        DataExtDefAddRq.DataExtListRequire.SetValue(true);
                        //Set field value for DataExtTxnRequire
                        DataExtDefAddRq.DataExtTxnRequire.SetValue(true);
                        //Set field value for DataExtFormatString
                        DataExtDefAddRq.DataExtFormatString.SetValue("ab");
                        //Set field value for IncludeRetElementList
                        //May create more than one of these if needed
                        DataExtDefAddRq.IncludeRetElementList.Add("ab");
                }




                void WalkDataExtDefAddRs(IMsgSetResponse responseMsgSet)
                {
                        if (responseMsgSet == null) return;
                        IResponseList responseList = responseMsgSet.ResponseList;
                        if (responseList == null) return;
                        //if we sent only one request, there is only one response, we'll walk the list for this sample
                        for(int i=0; i < responseList.Count; i++)
                        {
                                IResponse response = responseList.GetAt(i);
                                //check the status code of the response, 0=ok, >0 is warning
                                if (response.StatusCode >= 0)
                                {
                                        //the request-specific response is in the details, make sure we have some
                                        if (response.Detail != null)
                                        {
                                                //make sure the response is the type we're expecting
                                                ENResponseType responseType = (ENResponseType)response.Type.GetValue();
                                                if (responseType == ENResponseType.rtDataExtDefAddRs)
                                                {
                                                        //upcast to more specific type here, this is safe because we checked with response.Type check above
                                                        IDataExtDefRet DataExtDefRet = (IDataExtDefRet)response.Detail;
                                                        WalkDataExtDefRet(DataExtDefRet);
                                                }
                                        }
                                }
                        }
                }




                void WalkDataExtDefRet(IDataExtDefRet DataExtDefRet)
                {
                        if (DataExtDefRet == null) return;
                        //Go through all the elements of IDataExtDefRet
                        //Get value of OwnerID
                        if (DataExtDefRet.OwnerID != null)
                        {
                                string OwnerID7825 = (string)DataExtDefRet.OwnerID.GetValue();
                        }
                        //Get value of DataExtID
                        int DataExtID7826 = (int)DataExtDefRet.DataExtID.GetValue();
                        //Get value of DataExtName
                        string DataExtName7827 = (string)DataExtDefRet.DataExtName.GetValue();
                        //Get value of DataExtType
                        ENDataExtType DataExtType7828 = (ENDataExtType)DataExtDefRet.DataExtType.GetValue();
                        //Get value of AssignToObjectList
                        if (DataExtDefRet.AssignToObjectList != null)
                        {
                                ENAssignToObjectList AssignToObject7829 = (ENAssignToObjectList)DataExtDefRet.AssignToObjectList.GetValue();
                        }
                        //Get value of DataExtListRequire
                        bool DataExtListRequire7830 = (bool)DataExtDefRet.DataExtListRequire.GetValue();
                        //Get value of DataExtTxnRequire
                        bool DataExtTxnRequire7831 = (bool)DataExtDefRet.DataExtTxnRequire.GetValue();
                        //Get value of DataExtFormatString
                        string DataExtFormatString7832 = (string)DataExtDefRet.DataExtFormatString.GetValue();
                }




        }
}