Execute function for two minutes or until nested function responds true in Business central

PablogrindPablogrind Member Posts: 13
Hi

I need execute TryCallData for two minutes or until GetPDF responds true

How can i do it in Business central?, Thanks
procedure GetPDF(Bill: text) ReturnPDF: Boolean
    begin
        <Statement>  
    end;


procedure TryCallData()
    begin

        while not GetPDF('HMO986') do
            message('waiting...');

    end;

Best Answer

  • txerifftxeriff Member Posts: 501
    Answer ✓
    Pablogrind wrote: »
    thanks @txeriff Is there a way to stop if loop takes more than 2 minutes?

    Hi,

    Not sure what you trying to run on GetPDF but if you want to wait 2 minutes try

    getpdf('');
    sleep(10800); //seconds
    and thats it.


    it won´t be time but I don´t want now to write you the whole code´(and time calculations are always pain), just use a counter :

    vcounter:=0;
    repeat
    vcounter+=1;
    until vcounter>=10800

    for time:

    vTime:=TIME;

    SLEEP(3000); //wait 3 seconds
    vTimeDec:=TIME-vTime;

    MESSAGE(FORMAT(vTimeDec)); //time difference

Answers

  • txerifftxeriff Member Posts: 501
    edited 2021-02-18
    Dear god, this is basic coding issue:
    procedure TryCallData()
    var vFinished: boolean;
        begin
            vfinished:=false;
            repeat
                 vfinished:=GetPDF('HMO986');
             until vfinished=true;
    
        end;
    
  • PablogrindPablogrind Member Posts: 13
    thanks @txeriff Is there a way to stop if loop takes more than 2 minutes?
  • txerifftxeriff Member Posts: 501
    Answer ✓
    Pablogrind wrote: »
    thanks @txeriff Is there a way to stop if loop takes more than 2 minutes?

    Hi,

    Not sure what you trying to run on GetPDF but if you want to wait 2 minutes try

    getpdf('');
    sleep(10800); //seconds
    and thats it.


    it won´t be time but I don´t want now to write you the whole code´(and time calculations are always pain), just use a counter :

    vcounter:=0;
    repeat
    vcounter+=1;
    until vcounter>=10800

    for time:

    vTime:=TIME;

    SLEEP(3000); //wait 3 seconds
    vTimeDec:=TIME-vTime;

    MESSAGE(FORMAT(vTimeDec)); //time difference
  • PablogrindPablogrind Member Posts: 13
    Thanks @txeriff
Sign In or Register to comment.