ReportEngine.SetReportProperties allows you to change the properties of a report when the user selects it in the Reports Explorer. Also, if the script returns False, Stonefield Query displays a warning message that the report is unavailable to the user and they cannot run it or edit it.
Parameters
A reference to the Stonefield Query Application object and a reference to a Report object for the report.
Return Value
True if the user can access the report, False to flag the report as unavailable to this user.
Example
Suppose you rename the STATE field in the CUSTOMERS table to REGION in version 2.0 of your application. As a result, any report designed in version 1.0 using that field won't work in 2.0 because the STATE field no longer exists. So, the following code renames the STATE field to REGION if it exists in the selected report. The code starts by putting all the existing fields into an array so we can put them back into the fields collection later if necessary. It then renames STATE to REGION if that field is found. If the name was changed, the code updates the collection since we can't change the name of objects in the collection because name is used as the object's key.
Visual FoxPro
lparameters toApplication as SQApplication, toReport as Report
local lnFields, ;
laFields[1], ;
lnI, ;
loField, ;
llNewName
lnFields = toReport.Fields.Count
dimension laFields[lnFields]
for lnI = 1 to lnFields
loField = toReport.Fields.Item(lnI)
laFields[lnI] = loField
if loField.FieldName = 'Customers.State'
loField.FieldName = 'Customers.Region'
llNewName = .T.
endif
next
if llNewName
toReport.Fields.Clear()
for lnI = 1 to lnFields
loField = laFields[lnI]
toReport.Fields.AddItem(loField)
next
endif
return .T.
VBScript
function Main(Application, Report)
dim Fields(1), Field
FieldCount = Report.Fields.Count
redim Fields(FieldCount)
NewName = False
for I = 1 to FieldCount
set Field = Report.Fields.Item(I)
set Fields(I) = Field
if Field.FieldName = "Customers.State" then
Field.FieldName = "Customers.Region"
NewName = True
end if
next
if NewName then
Report.Fields.Clear()
for I = 1 to FieldCount
set Field = Fields(I)
Report.Fields.AddItem Field
next
end if
Main = True
end function
JavaScript
function Main(Application, Report) {
var FieldCount, Fields, NewName, I, Field ;
FieldCount = Report.Fields.Count ;
Fields = new Array(FieldCount) ;
NewName = false ;
for (I = 1; I <= FieldCount; I++) {
Field = Report.Fields.Item(I) ;
Fields[I] = Field ;
if (Field.FieldName = "Customers.State") {
Field.FieldName = "Customers.Region" ;
NewName = true ;
}
}
if (NewName = true) {
Report.Fields.Clear() ;
for (I = 1; I <= FieldCount; I++) {
Field = Fields[I] ;
Report.Fields.AddItem(Field) ;
}
}
return true ;
}
C#
Please note that the method in this script must be named ReportEngine_SetReportProperties.
public static void ReportEngine_SetReportProperties(SFQApplication sfqApplication,
Report report)
{
bool newName = false;
int fieldCount = report.Fields.Count;
ReportField[] fields = new ReportField[fieldCount];
for(int i = 0; i < fieldCount; i++)
{
fields[i] = report.Fields[i];
if(fields[i].FieldName == "Customers.State")
{
fields[i].FieldName = "Customers.Region";
newName = true;
}
}
if (newName)
{
report.Fields.Clear();
for (int i = 0; i < fieldCount; i++)
{
report.Fields.AddItem(fields[i]);
}
}
return true;
}
VB.NET
Please note that the method in this script must be named ReportEngine_SetReportProperties.
public shared function
ReportEngine_SetReportProperties(sfqApplication as SFQApplication,
report as Report) as Boolean
Dim newName As Boolean = False
Dim fieldCount As Integer = report.Fields.Count
Dim fields(fieldCount) As ReportField
For i As Integer = 0 To fieldCount - 1
fields(i) = report.Fields(i)
If fields(i).FieldName = "Customers.State" Then
fields(i).FieldName = "Customers.Region"
newName = True
End If
Next
If newName Then
report.Fields.Clear()
For i As Integer = 0 To fieldCount - 1
report.Fields.AddItem(fields(i))
Next
End If
Return True
End Function
See also
Report Object | Scripts© Stonefield Software Inc., 2023 • Updated: 01/13/17
Comment or report problem with topic