Thursday, September 20, 2018

Web Service > .NET > Sample Code > AsyncAddList: Entity Records


In asynchronous requests, your client application sends a request to the SuiteTalk Platform where it is placed in a processing queue and handled asynchronously with other requests.
 
This article requires existing knowledge of Web Services and .NET. In this example three customer records will be added and the response of the request will be stored in a string value. 


Sample code snippet:

NetSuiteService _service = new NetSuiteService();
string jobId;
double percentage;
string[] customerList = {"Customer A","Customer B","Customer C"};
Customer[] customers = new Customer[customerList.Length];
for (int i = 0; i < customerList.Length; i++)
{
       customers[i] = new Customer();
       customers[i].companyName = customerList[i].ToString();
}
AsyncStatusResult response = _service.asyncAddList(customers);
jobId = response.jobId;
percentage = response.percentCompleted;
 


 
The above code would generate the following SOAP request/response:

< Envelope>
    < Header/>
    < Body>
        <addList>
            <record type="Customer">
                <companyName>Customer A</companyName>
            </record>
            <record type="Customer">
                <companyName>Customer B</companyName>
            </record>
            <record type="Customer">
                <companyName>Customer C</companyName>
            </record>
        </addList>
    </ Body>
</ Envelope>

 
<Envelope>
    <Header>
        <documentInfo>
            <nsId>ASYNCWEBSERVICES_TSTDRV570143_0202201018783705721297302776_e</nsId>
        </documentInfo>
    </Header>
    <Body>
        <addListResponse>
            <writeResponseList>
                <writeResponse>
                   <status isSuccess="true"/>
                    <baseRef type="RecordRef" type="customer" internalId="172"/>
                </writeResponse>
                <writeResponse>
                    <status isSuccess="true"/>
                    <baseRef type="RecordRef" type="customer" internalId="173"/>
                </writeResponse>
                <writeResponse>
                    <status isSuccess="true"/>
                    <baseRef type="RecordRef" type="customer" internalId="174"/>
                </writeResponse>
            </writeResponseList>
        </addListResponse>
    </Body>
</Envelope>

 

No comments:

Post a Comment