justindoh
New member
- Joined
- Dec 12, 2021
- Messages
- 4
- Programming Experience
- 1-3
Sorry, I am not good at C#..
I am trying to write Looping for the result of data collected from each API call.
Because it is API, it has certain limitation ("PageSize") to collect data each time.
Currently, it has "PageSize" of 2000, and it increments by that value (2000).
"Offset" points where data retrieval starts.
I am trying to write For or For Each or whatever that collects all data together until "clinet.Execute(query)" ends.
By looking at the data, it appears that "result.NumRemaining = 0 or response.Results.NumRemaining = 0" should be the end point where looping should end.
Below is image of where objects for the query are declared and I personally wrote two more lines to declare two objects (where it starts with: int? offset.. and int? pagesize..) to be used for looping.
I am not sure these two lines (where it starts with: int? offset.. and int? pagesize..) should go before it has "Result result = response.Result[0]" or not.
I am stuck how to use "result.NumRemaining = 0" to used inside Looping and also how to express to collect data together.
Bottom is whole code:
How do I express Looping?
Thanks.
I am trying to write Looping for the result of data collected from each API call.
Because it is API, it has certain limitation ("PageSize") to collect data each time.
Currently, it has "PageSize" of 2000, and it increments by that value (2000).
"Offset" points where data retrieval starts.
I am trying to write For or For Each or whatever that collects all data together until "clinet.Execute(query)" ends.
By looking at the data, it appears that "result.NumRemaining = 0 or response.Results.NumRemaining = 0" should be the end point where looping should end.
Below is image of where objects for the query are declared and I personally wrote two more lines to declare two objects (where it starts with: int? offset.. and int? pagesize..) to be used for looping.
I am not sure these two lines (where it starts with: int? offset.. and int? pagesize..) should go before it has "Result result = response.Result[0]" or not.
I am stuck how to use "result.NumRemaining = 0" to used inside Looping and also how to express to collect data together.
Bottom is whole code:
LoopQuestion:
public static string Run(ILogger logger)
{
OnlineClient client = Bootstrap.Client(logger);
SelectBuilder selectBuilder = new SelectBuilder();
ISelect[] fields = selectBuilder.
Fields(new[] { "RECORDNO","VENDORID", "VENDORNAME", "TOTALPAID"}).
GetFields();
// trying to increase Offset by 2,000 each time until result = 0
QueryFunction query = new QueryFunction()
{
FromObject = "APBILL",
Offset = 0, // (0, 2000, 4000, 6000 etc..)
PageSize = 2000,
SelectFields = fields
};
Task<OnlineResponse> task = client.Execute(query);
OnlineResponse response = task.Result;
// ***** I wrote these two following lines..
int? offset = query.Offset;
int? pagesize = query.PageSize;
Result result = response.Results[0];
//for (offset = 0; response.Result = 0; pagesize++) <--- ***** I tried to write Looping here....
// Get the result
// Convert into Json
if (result.Count > 0)
{
dynamic resultJson =
JsonConvert.DeserializeObject(JsonConvert.SerializeObject(result.Data));
string resultJsonString = resultJson.ToString();
return resultJsonString;
}
return "";
}
How do I express Looping?
Thanks.
Last edited: