Submit

Description

Sends the data to the server via the HTTP POST method and then gets the response body from the server.

It is not recommended to use this method to process large data (20 MB or 100,000 data rows can be considered as large data based on our tests).

Applies to

RestClient object

Syntax

objectname.Submit(string urlName, ref string response, DWControl dwObject{, boolean format})
objectname.Submit(string urlName, ref string response, DWControl dwObject {,DWBuffer dwbuffer}, boolean changedonly, boolean format)
objectname.Submit(string urlName, ref string response, DWControl dwObject, boolean primarydata, boolean filterdata, boolean deletedata, boolean dwcdata {, boolean format})
objectname.Submit(string urlName, ref string response, DWControl dwObject, DWBuffer dwbuffer{,long startrow{, long endrow{, long startcol{, long endcol}}}} {, boolean format}) 
objectname.Submit(string urlName, ref string response, ref JsonPackage package)

Argument

Description

objectname

The name of the RESTClient object.

urlName

The URL indicating where the data will be submitted.

response

The content of the server response.

If RESTClient failed to send request or server provides no response, the response value is an empty string. If the response value is compressed as gzip, it will be automatically decompressed. Only gzip compression format is supported at this moment. If the server specified the Content-Type response header, and in which the encoding charset is specified, this function will encode the data with the specified charset, if charset is not specified, this function will encode the data in UTF-8 by default.

dwObject

The DataWindow control, DataStore, or DataWindowChild object whose data will be submitted.

primarydata

A boolean indicating whether to export and submit the data from the primary buffer.

  • True -- to export.

  • False -- not to export.

filterdata

A boolean indicating whether to export and submit the data from the filter buffer.

  • True -- to export.

  • False -- not to export.

deletedata

A boolean indicating whether to export and submit the data from the delete buffer.

  • True -- to export.

  • False -- not to export.

dwcdata

A boolean specifying whether to export the DataWindowChild data.

  • True -- to export. If it is to export the DataWindowChild data, data from all buffers will be exported to a plain JSON, regardless of the value of the other arguments.

  • False -- not to export.

dwbuffer

A value of the dwBuffer enumerated datatype identifying the DataWindow buffer from which you want to export the data. For a list of valid values, see the section called “DWBuffer” in DataWindow Reference.

If not specified, all of the DataWindow buffers will be exported, however, the data for DataWindowChild will not be exported (even if changedonly is false).

startrow (optional)

A long value specifying the start row in the dwbuffer DataWindow buffer. The default is 1. If it is 0 or negative, 1 is used.

endrow (optional)

A long value specifying the end row in the dwbuffer DataWindow buffer. The default is the rest of the rows. If it is 0 or negative, it indicates the rest of rows.

startcol (optional)

A long value specifying the start column in the dwbuffer DataWindow buffer. The default is 1. If it is 0 or negative, 1 is used.

endcol (optional)

A long value specifying the end column in the dwbuffer DataWindow buffer. The default is the rest of the columns. If it is 0 or negative, it indicates the rest of columns.

changedonly

A boolean specifying the changing flag.

  • True -- to export the changed rows only (and all rows of the Delete buffer).

  • False -- to export all rows. The default is false.

format (optional)

A boolean specifying the JSON format.

  • True indicates the DataWindow JSON. For syntax 1, 3, 4, the default is true.

  • False indicates the plain JSON. For syntax 2, the default is false.

See the section called “Supported JSON formats” in Application Techniques for details about the JSON format.

package

A reference to JsonPackage object whose data will be submitted.


Return value

Integer. Returns 1 if the function succeeds and a negative value if an error occurs. If any argument's value is null, the method returns null.

1 -- Success

-1 -- General error

-2 -- Invalid URL

-3 -- Cannot connect to the Internet

-4 -- Timeout

-6 -- Failed to export JSON

-7 -- Failed to decompress data

-10 -- The token is invalid or has expired

-14 -- Code conversion failed

-15 -- Unsupported character set

Usage

Syntax 1 submits the data of the DataWindow primary buffer only. If you want to submit the data of the other DataWindow buffers, use Syntax 2 or 3.

Examples

The following example demonstrates the usage of syntax 1: Submit(string urlName, ref string response, DWControl dwObject{, boolean format}).

String ls_P025_ResponseBody
Integer li_P025_SendReturn
RestClient lrc_P025
lrc_P025 = Create RestClient
lrc_P025.SetRequestHeaders( "Content-Type:application/json;charset=UTF-8~r~nAccept-Encoding:gzip" )

lrc_P025.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve")
//Modifies the data in dw_Data
If dw_Data.GetRow() > 0 Then 
 dw_Data.SetItem(dw_Data.GetRow(), 2, "Test submit")
 //.... 
End If
//Uses the DataWindow JSON
//Server determines whether to update according to the data state
//DataWindow column name and type must match with that of server
li_P025_SendReturn = lrc_P025.submit ("https://demo.appeon.com/PB/webapi_client/department/updateByJson",ls_P025_Responsebody, dw_Data,True)

If li_P025_SendReturn <> 1 Or lrc_P025.GetResponseStatusCode() <> 200 Then
 //Checks if any error information 
End If

//Finds out if data is updated via https://demo.appeon.com/PB/webapi_client/api/department/retrieve
lrc_P025.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve")

The following example submits the data of the DataWindow primary buffer using syntax 2: Submit(string urlName, ref string response, DWControl dwObject {,DWBuffer dwbuffer}, boolean changedonly, boolean format).

String ls_P025_ResponseBody
Integer li_P025_SendReturn
RestClient lrc_P025
lrc_P025 = Create RestClient
lrc_P025.SetRequestHeaders( "Content-Type:application/json;charset=UTF-8~r~nAccept-Encoding:gzip" )

lrc_P025.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve")
//Modifies the data in dw_Data
If dw_Data.GetRow() > 0 Then 
 dw_Data.SetItem(dw_Data.GetRow(), 2, "Test submit primary")
 //.... 
End If
//Uses the DataWindow JSON
//Server determines whether to update according to the data state
//DataWindow column name and type must match with that of server
li_P025_SendReturn = lrc_P025.Submit("https://demo.appeon.com/PB/webapi_client/department/updateByJson",ls_P025_Responsebody, dw_Data,Primary!, True, True)
If li_P025_SendReturn <> 1 Or lrc_P025.GetResponseStatusCode() <> 200 Then
 //Checks if any error information
End If

//Finds out if data is updated via https://demo.appeon.com/PB/webapi_client/api/department/retrieve
lrc_P025.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve")

The following example submits the data of the DataWindow delete buffer using syntax 3: Submit(string urlName, ref string response, DWControl dwObject, boolean primarydata, boolean filterdata, boolean deletedata, boolean dwcdata {, boolean format}).

String ls_P025_ResponseBody
Integer li_P025_SendReturn
RestClient lrc_P025
lrc_P025 = Create RestClient
lrc_P025.SetRequestHeaders( "Content-Type:application/json;charset=UTF-8~r~nAccept-Encoding:gzip" )

lrc_P025.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve")
//Modifies the data in dw_Data
If dw_Data.RowCount() > 0 Then 
 dw_Data.DeleteRow( dw_Data.RowCount())
 //.... 
End If
//Uses the DataWindow JSON
//Server determines whether to update according to the data state
//DataWindow column name and type must match with that of server
li_P025_SendReturn = lrc_P025.Submit("https://demo.appeon.com/PB/webapi_client/department/updateByJson", ls_P025_Responsebody, dw_Data, False, False, True, False, True)
If li_P025_SendReturn <> 1 Or lrc_P025.GetResponseStatusCode() <> 200 Then
 //Checks if any error information
End If

//Finds out if data is deleted via https://demo.appeon.com/PB/webapi_client/api/department/retrieve
lrc_P025.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve")

The following example submits the data of the specified row and column using syntax 4: Submit(string urlName, ref string response, DWControl dwObject, DWBuffer dwbuffer{,long startrow{, long endrow{, long startcol{, long endcol}}}} {, boolean format}).

String ls_P025_ResponseBody
Integer li_P025_SendReturn
RestClient lrc_P025
lrc_P025 = Create RestClient
lrc_P025.SetRequestHeaders( "Content-Type:application/json;charset=UTF-8~r~nAccept-Encoding:gzip" )

//Retrieves data for dw_Data
lrc_P025.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve")
//Modifies the data in dw_Data
If dw_Data.GetRow() > 0 Then 
 dw_Data.SetItem( dw_Data.GetRow(), 2,"Submit row col"+String(rand(100)))
 dw_Data.SetItem( dw_Data.GetRow(), 3,rand(1000))
 //.... 
End If
//Uses the DataWindow JSON
//Server determines whether to update according to the data state
//DataWindow column name and type must match with that of server
li_P025_SendReturn = lrc_P025.Submit("https://demo.appeon.com/PB/webapi_client/department/updateByJson", ls_P025_Responsebody, dw_Data, Primary!,1, 2, 1, 2)
If li_P025_SendReturn <> 1 Or lrc_P025.GetResponseStatusCode() <> 200 Then
 //checke the failed information 
End If

//Finds out if data of column 2 is updated via https://demo.appeon.com/PB/webapi_client/api/department/retrieve
lrc_P025.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve")

The following example submits data via JSONPackage object and token authentication using syntax 5: Submit(string urlName, ref string response, ref JsonPackage package).

JsonPackage ljpk_submit
RestClient lrc_JPK_Submit
String ls_P017_Token
String ls_Submit_Responsebody
Integer li_JsonpackageSetValueReturn
Integer li_P017_GetTokenReturn
Integer li_SubmitReturn

ljpk_submit = Create JsonPackage
lrc_JPK_Submit = Create RestClient

//Sets the token parameters
TokenRequest ltreq_P017_Appeon
ltreq_P017_Appeon.tokenlocation = "https://demo.appeon.com/pb/identityserver/connect/token"
ltreq_P017_Appeon.method = "post"
ltreq_P017_Appeon.GrantType = "password"
ltreq_P017_Appeon.ClientId = "P0VRQ-ddHn/WWd6lcCNJbaO9ny-JCNHirDJkHNgZ0-M="
ltreq_P017_Appeon.ClientSecret = "K7gNU3sdo-OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=" 
ltreq_P017_Appeon.UserName = "TestUser"
ltreq_P017_Appeon.PassWord = "TestPassword"

//Gets token via RESTClient
li_P017_GetTokenReturn = lrc_JPK_Submit.GetOauthtoken( ltreq_P017_Appeon, ls_P017_Token)
If li_P017_GetTokenReturn = 1 Then
 lrc_JPK_Submit.SetRequestHeaders( "Content-Type:application/json;charset=UTF-8~r~nAccept-Encoding:gzip" )
 lrc_JPK_Submit.SetOauthToken( ls_P017_Token ) //Sets the authentication 
 lrc_JPK_Submit.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve")
  //Modifies data
  If dw_Data.GetRow() >0 Then
   dw_Data.SetItem(dw_Data.GetRow(),2,"Test submit from jsonpackage"+String(rand(100)))
   //...
  End If
 //Value of JSONPackage comes from dw_Data
 li_JsonpackageSetValueReturn = ljpk_submit.setvalue( "AppeonJsonPackageKey", dw_Data, True) 
  
 //Submits the DataWindow data to server
 //Requires token authentication
 //DataWindow column name and type must match with that of server
 li_SubmitReturn = lrc_JPK_Submit.Submit( "https://demo.appeon.com/PB/webapi_client/identity/department/UpdateByJsonPackage",ls_Submit_Responsebody, ljpk_submit)
  If li_SubmitReturn <> 1 Or lrc_JPK_Submit.GetResponseStatusCode() <> 200 Then
   //Checks if any error information and checks the submit parameter: ls_Submit_Responsebody 
  End If
 
 //Finds out if data is updated via https://demo.appeon.com/PB/webapi_client/api/department/retrieve
 lrc_JPK_Submit.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve")
End If