I am attempting to schedule a report from code. I am currently running, on Server 2008, BO 4.0, BO Service Pack 4.0.9. and .NET SDK 14.0.4. When the code tries to set the value for a parameter for a CeReportVariableValueType = ceRVDateTime, I get the following error "One or more arguments are invalid" when trying to set the "parmValue.SingleValue.Value = dateParm" (see highlighted code below). I tried to reformat the date a number of different ways, but have had no luck.
Below is the code for scheduling the report. The code does work for reports that do not have a datetime parameter.
Any help would be greatly appreciated,
Angela
private void ScheduleReportWithParameters(string reportName, ArrayList parameters, SmtpData smtpData)
{
//Retrieves report by report name
string rptQuery = "SELECT * FROM CI_INFOOBJECTS WHERE SI_NAME='" + reportName + "' AND SI_INSTANCE = 0";
InfoObjects infoObjects = infoStore.Query(rptQuery);
InfoObject infoObject = infoObjects[1];
report = new Report(infoObject.PluginInterface);
//Setting scheduling info
SchedulingInfo schedulingInfo = report.SchedulingInfo;
schedulingInfo.Type = CeScheduleType.ceScheduleTypeOnce;
schedulingInfo.RightNow = true;
//Retrieves SMPT Settings, SI_PARENTID must be equal to 29
var smtpQuery = "SELECT SI_DEST_SCHEDULEOPTIONS, SI_PROGID FROM CI_SYSTEMOBJECTS WHERE SI_PARENTID=29 and SI_NAME='CrystalEnterprise.SMTP'";
InfoObjects destinationInfoObjects = infoStore.Query(smtpQuery);
infoObject = destinationInfoObjects[1];
DestinationPlugin destinationPlugin = (DestinationPlugin)infoObject;
Smtp smtp = (Smtp)destinationPlugin;
DestinationOptions destinationOptions = smtp.ScheduleOptions;
SmtpOptions smtpOptions = new SmtpOptions(destinationOptions);
smtpOptions.CCAddresses.Add(smtpData.CcAddresses);
smtpOptions.ToAddresses.Add(smtpData.ToAddresses);
smtpOptions.Attachments.Add(report.MimeType, smtpData.AttachmentPath + ".%EXT%");
smtpOptions.Subject = smtpData.Subject;
smtpOptions.Message = smtpData.Body;
schedulingInfo.Destination.SetFromPlugin(smtp);
//Setting Report parameters
ReportParameters reportParameters = report.ReportParameters;
for (int i = 1; i <= reportParameters.Count; i++)
{
ReportParameter reportParameter = reportParameters[i];
reportParameter.CurrentValues.Clear();
ReportParameterValue parmValue = reportParameters[i].CreateSingleValue();
if (reportParameter.ValueType == CeReportVariableValueType.ceRVDateTime)
{
var dateParm = string.Format("DateTime(" + parameters[i - 1].ToString().Replace("/", ", ") + ", 00, 00, 00)");
parmValue.SingleValue.Value = dateParm;
}
else if (reportParameter.ValueType == CeReportVariableValueType.ceRVDate)
{
var dateParm = "DateTime(" + parameters[i - 1].ToString().Replace("/", ", ") + ")";
parmValue.SingleValue.Value = dateParm;
}
else
{
parmValue.SingleValue.Value = parameters[i - 1].ToString();
}
reportParameter.CurrentValues.Add(parmValue);
}
//Sending scheduled report to server
InfoObjects infoObjectsParent = report.ParentInfoObjects;
infoStore.Schedule(infoObjectsParent);
}