IScheduledTask.ExecuteImmediate

Syntax

ExecuteImmediate(SaveResult: Boolean): IScheduledTaskResult;

Parameters

SaveResult. It determines whether the task execution result should be saved into the database. Available values:

Description

The ExecuteImmediate method executes a task in current repository.

Comments

The ExecuteImmediate method executes the task in the current process and current repository and running task scheduler is not required. Settings of the message sending about the task execution and saving of the result on the FTP server are ignored.

Example

Executing the example requires that the repository has a scheduled tasks container with the SCHEDULEDTASKSCONTAINER identifier. and calculation task of regular report with the REPORT_TASK identifier. Any action with execution result should be set up for this task.

Add links to the Fore, IO, Metabase system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    Cont: IScheduledTasksContainer;
    Tasks: IMetabaseObjectDescriptors;
    i: Integer;
    Task: IScheduledTask;
    Result: IScheduledTaskResult;
    FileName: string;
    Stream: IIOStreamSys;
Begin
    
// Get current repository
    MB := MetabaseClass.Active;
    Cont := MB.ItemById(
"SCHEDULEDTASKSCONTAINER").Bind As IScheduledTasksContainer;
    
// Get task with the REPORT_TASK identifier
    Tasks := Cont.Tasks;
    
For i := 0 To Tasks.Count - 1 Do
        
If Tasks.Item(i).Id = "REPORT_TASK" Then
            Task := Tasks.Item(i).Edit 
As IScheduledTask;
        
End If;
    
End For;
    
// Perform task
    Result := Task.ExecuteImmediate(True);
    
// Save execution results to file
    If Result.HasDataStream Then
        FileName := 
"c:\" + (Task As IMetabaseObject).Name + "." + Result.FileExtension;
        Stream := 
New FileStream.Create(FileName, FileOpenMode.Create, FileShare.Exclusive) As IIOStreamSys;
        Result.ReadDataStream(Stream);
        Debug.WriteLine(
"Result is saved to file " + FileName);
    
End If;
End Sub UserProc;

After executing the example the task will be executed, the obtained result will be saved to the file which name will be displayed to the console window.

See also:

IScheduledTask