RetrieveWithModel

Description

Retrieves data for one DataWindow, DataWindowChild, or DataStore using the .NET DataStore Web API.

Applies to

RestClient object

Syntax

objectname.RetrieveWithModel (dwControl, urlName {, tokenrequest} {, param1, param2, param3…})

Argument

Description

objectname

A reference to the RestClient object.

dwControl

The name of the DataWindow control, DataStore, or child DataWindow.

urlName

A string whose value is the URL of the .NET DataStore Web API.

tokenrequest

(Optional) A reference to the TokenRequest object for supporting OAuth 2.0. If this parameter is used, the token settings in the SetOAuthToken and SetJWTToken functions will be ignored.

param

(Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement defined in dwcontrol. (it can be an array)


Usage

When using RetrieveWithModel to retrieve data to a DataWindow, the DataWindowChild of the DataWindow will be synced with the retrieved data (same behavior as with PowerServer).

Limitation of RetrieveWithModel with dynamic DataWindows

RetrieveWithModel works with .NET DataStores that are built from static C# models in a Web API application. It sends the DataWindow object's name and retrieval parameters to the Web API; the Web API then uses the corresponding C# model to build the DataStore, run its SQL SELECT, and return the results.

RetrieveWithModel does not support DataWindows that are dynamically created in PowerBuilder or have SQL SELECT statements changed at runtime, because the method relies on predefined C# models and SQL and it cannot handle any runtime changes or custom SQL logic defined dynamically within the PowerBuilder client.

To use dynamic SQL or create DataWindows at runtime, you should add custom API endpoints in your Web API project. These endpoints can accept custom requests and run the needed SQL. You can then use methods like RestClient.SendPostRequest from the PowerBuilder client to call these APIs and handle dynamic data as needed.

Return value

Long.

Returns the number of rows if it succeeds and a negative value if an error occurs. If any argument's value is null, the method returns null.

Example

The following code example shows retrieving data for dw_emp using a .NET DataStore Web API:

long ll_return
RestClient lnv_RestClient
lnv_RestClient = Create RestClient

// Retrieve data via .NET DataStore Service
ll_return = lnv_RestClient.RetrieveWithModel(dw_emp, "http://localhost:5099/RetrieveWithModel", 102)

// Check the return value
if ll_return >= 0 then
    MessageBox("Success", "Rows = " + String(ll_return))
else
    MessageBox("Error", "Failed to retrieve data.")
end if

See also

RetrieveOrUpdateWithModels

UpdateWithModel