RawInvokeAsync not working properly as it goes to next method instead of executing next line from same method. Is there any setting for calling the RawInvokeAsync method?

Hi,

I am using RawInvokeAsync method to call Xdata api service methods but it seems not behaving properly. As you can see on following codes the method LoadCodeLookup is using async property to call RawInvokeAsync methods to get Codes lookup. The method LoadCustomerData is used to get a single Customer data where the custid=1. I am calling both the methods on webformshow event but it fails to call the LoadCodeLookup method in Async. As before loading data to XDataWebDataset1 in LoadCodeLookUp method the pointer goes to LoadCustomerData and executes that first.

Is this correct behavior? if yes, then how to make sure that it will execute the whole LoadCodeLookup method 1st with loading data into XDataWebDataset1 and then goes to LoadCustomerData method.

Following are webform codes...

type
  TfrmCustomerEditor = class(TWebForm)
..........
    procedure WebFormShow(Sender: TObject);
  private
    { Private declarations }
    [async]
    procedure LoadCodeLookup;

    procedure LoadCustomerData;
end;

implementation

{$R *.dfm}

procedure TfrmCustomerEditor.LoadCodeLookup;
var
    res: TXDataClientResponse;
begin
    res := await(XDataWebClient1.RawInvokeAsync('IcustomerService.GetCodeLookups', [LoggedUserId]));
   
    XDataWebDataset1.Close; // this line not executing after the above line execute. the pointer goes to LoadCustomerData method//
    XDataWebDataset1.SetJsonData(TJSObject(res.Result)['value']);
    XDataWebDataset1.Open;
end;

procedure TfrmCustomerEditor.LoadCustomerData;
begin
  //this method code executes before loading data into XDataWebDataset1 in LoadCodeLookup method//
  webdsCustomer.Close;
  webdsCustomer.EntitySetName := 'Customer';
  webdsCustomer.QueryString := '$filter=custid eq 1';
  webdsCustomer.Load;
end;

procedure TfrmCustomerEditor.WebFormShow(Sender: TObject);
begin
// it no behaving as async method call//
  LoadCodeLookup;

  LoadCustomerData;
end;

On above codes, when it executes the LoadCodeLookup method block's RawInvokeAsync method calling line then execution pointer goes to LoadCustomerData method instead of executing XDataWebDataset1.Close; line from LoadCodeLookup.

So is there any specific setting, units required to make the RawInvokeAsync calling work?
I am using following TMS product versions

Appreciate you help.

Did you try decorating the WebFormShow type declaration with [async] and using await in its first call, as the following?

procedure TfrmCustomerEditor.WebFormShow(Sender: TObject);
begin
  await (LoadCodeLookup);
  LoadCustomerData;
end;
1 Like

@Peterson_Terry is correct. LoadCodeLookup is an async method, if you want to make sure LoadCustomerData executes after LoadCodeLookup is completed, you have to call the latter with async.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.