The ReportEngine.AfterGetFolders script is called after a collection of report folders the user has access to has been retrieved but before these folders are displayed in the Reports Explorer. This script allows you to modify this collection if, for example, you want to only display certain folders under certain conditions.

Parameters
A reference to the Stonefield Query Application object and a collection containing objects with information about the folders. These objects have a FolderName property containing the name of the folder.

Return Value
Any value (Stonefield Query ignores the return value).

Example
Here's an example that allows you to display the reports in only a single folder in the Reports Explorer. For example, an accounting application may have menu items that allow the user to see General Ledger Reports, Payroll Reports, Accounts Payable Reports, and so forth. When the user chooses the appropriate menu item, the application calls Stonefield Query, passing it the name of the folder to display as a parameter (the parameters passed to Stonefield Query are available in the Application object's Parameters collection). All other folders are removed from the in-memory collection (not permanently from the reports table).

Visual FoxPro

lparameters toApplication as SQApplication, ;
  toFolders as Collection
local lcFolder, lnI, loFolder
lcFolder = GetParameterValue('folder')
if not empty(lcFolder)
  for lnI = toFolders.Count to 1 step -1
    loFolder = toFolders.Item(lnI)
    if not loFolder.FolderName == lcFolder
      toFolders.Remove(lnI)
    endif
  next
endif

VBScript

function Main(Application, Folders)
dim Parameter, Folder
for I = 1 to Application.Parameters.Count
  set Parameter = Application.Parameters.Item(I)
  if Parameter.Name = "folder" then
    set Folder = Parameter.Value
  end if
next
if Folder <> " " then
  for I = Folders.Count to 1 step -1
    set Folder = Folders.Item(I)
    if Folder.FolderName <> Folder then
      Folders.Remove(lnI)
    end if
  next
end if
end function

JavaScript

function Main(Application, Folders) {
var I, Parameter, Folder ;
for (I = 1; I <= Application.Parameters.Count; I++) {
  Parameter = Application.Parameters.Item(I) ;
  if (Parameter.Name = 'folder') {
    Folder = Parameter.Value ;
  }
}
if (Folder <> ' ') {
  for (I = Folders.Count; I <= 1; I++) {
    Folder = Folders.Item(I) ;
    if (Folder.FolderName <> Folder) {
      Folders.Remove(lnI) ;
    }
  }
}
}

C#

Please note that the method in this script must be named ReportEngine_AfterGetFolders.

public static void ReportEngine_AfterGetFolders(SFQApplication sfqApplication, 
  Folders folders)
{	
  string folderName = String.Empty;
  Parameter param = sfqApplication.Parameters.Item("folder");
  if(param != null)
  {
    folderName = (string)param.Value;
  }

  if(folderName != String.Empty)
  {
    for (int i = 0; i < folders.Count; i++) 
    {
      Folder folder = folders.Item(i);
      if (folder.FolderName.ToUpper() != folderName.ToUpper()) 
      {
        folders.RemoveItem(i);
      }
    }
  }
}

VB.NET

Please note that the method in this script must be named ReportEngine_AfterGetFolders.

public shared function ReportEngine_AfterGetFolders(sfqApplication as SFQApplication,
  folders as Folders) as Boolean
  Dim folderName as string = String.Empty
  Dim param as Parameter = sfqApplication.Parameters.Item("folder")
  if Not param Is Nothing
    folderName = param.Value
  End If

  if folderName <> String.Empty
    for i as integer = 0 To folders.Count
      Dim folder as Folder = folders.Item(i)
      if folder.FolderName.ToUpper() <> folderName.ToUpper()
        folders.RemoveItem(i)
      End If
    Next
  End If
  Return True
End Function

See also

Scripts

© Stonefield Software Inc., 2023 • Updated: 06/06/16
Comment or report problem with topic