Kentico CMS 6.0 Developer's Guide

Managing report values

Managing report values

Previous topic Next topic Mail us feedback on this topic!  

Managing report values

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a value and assigns it to a report.

 

private bool CreateReportValue()
{
    // Get report object by report code name
    ReportInfo report = ReportInfoProvider.GetReportInfo("MyNewReport");
 
    // If report exists
    if (report != null)
    {
        // Create new report value object
        ReportValueInfo newValue = new ReportValueInfo();
 
        // Set the properties
        newValue.ValueDisplayName = "My new value";
        newValue.ValueName = "MyNewValue";
        newValue.ValueQuery = "SELECT COUNT(DocumentName) FROM CMS_Document";
        newValue.ValueQueryIsStoredProcedure = false;
        newValue.ValueReportID = report.ReportID;
 
        // Save the report value
        ReportValueInfoProvider.SetReportValueInfo(newValue);
 
        return true;
    }
 
    return false;
}

 

The following example gets and updates a report value.

 

private bool GetAndUpdateReportValue()
{

  // Get the report value
  ReportValueInfo updateValue = ReportValueInfoProvider.GetReportValueInfo("MyNewValue");

    if (updateValue != null)
    {
        // Update the properties
        updateValue.ValueDisplayName = updateValue.ValueDisplayName.ToLower();
 
        // Save the changes
        ReportValueInfoProvider.SetReportValueInfo(updateValue);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates report values.

 

private bool GetAndBulkUpdateReportValues()
{
    // Prepare the parameters
    string where = "ValueName LIKE N'MyNewValue%'";
 
    // Get the data
    DataSet values = ReportValueInfoProvider.GetValues(where, null);
    if (!DataHelper.DataSourceIsEmpty(values))
    {
        // Loop through the individual items
        foreach (DataRow valueDr in values.Tables[0].Rows)
        {
            // Create object from DataRow
            ReportValueInfo modifyValue = new ReportValueInfo(valueDr);
 
            // Update the properties
            modifyValue.ValueDisplayName = modifyValue.ValueDisplayName.ToUpper();
 
            // Save the changes
            ReportValueInfoProvider.SetReportValueInfo(modifyValue);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a report value.

 

private bool DeleteReportValue()
{

  // Get the report value
  ReportValueInfo deleteValue = ReportValueInfoProvider.GetReportValueInfo("MyNewValue");

 
    // Delete the report value
    ReportValueInfoProvider.DeleteReportValueInfo(deleteValue);
 
    return (deleteValue != null);
}