Crystal Report

Business Objects – Get Crystal Report 2008 Prompts using InfoStore from CMS Repository

Posted on Updated on

I’m working on a POC where I created a crystal report 2008 report with some prompts then deployed the report into BO server.

I need to get the list of prompts (parameters) before generating the report and fortunately turns out that the prompt information is available in the CMS Repository, so by using the code snippet below, we can get the list of parameter names for a particular crystal report deployed in the BO server (CMS).

public static List<string> GetCrystalReportPrompts(int reportId, EnterpriseSession session)
{
    List<string> reportParameterList = new List<string>();

    string query = string.Format("SELECT SI_ID, SI_NAME, SI_PROCESSINFO.SI_PROMPTS FROM CI_INFOOBJECTS WHERE SI_ID = {0}", reportId);
    using (InfoStore iStore = (InfoStore)session.GetService("InfoStore"))
    {
        using (InfoObjects objList = iStore.Query(query))
        {
            if (objList != null)
            {
                InfoObject infoObj = objList[1];// InfoObjects collection is 1-based, not 0-based index

                #region Use Processing Info to get the prompts
                //ProcessingInfo procInfo = infoObj.ProcessingInfo;
                //Property promptsProperty = procInfo.Properties["SI_PROMPTS"];
                //noParameters = (int)promptsProperty.Properties["SI_NUM_PROMPTS"].Value;

                //foreach (Property prop in promptsProperty.Properties)
                //{
                //    if (prop.Name == "SI_NUM_PROMPTS") // Ignore the number of prompt property
                //        continue;

                //    string promptName = prop.Properties["SI_NAME"].Value.ToString();
                //    reportParameterList.Add(promptName);
                //}
                #endregion

                #region Cast to Report object to get the prompts (cleaner so we don't have to know the logic inside)
                Report rpt = infoObj as Report;
                if (rpt != null)
                {
                    foreach (CrystalDecisions.Enterprise.Desktop.ReportParameter parameter in rpt.ReportParameters)
                    {
                        reportParameterList.Add(new ReportParameter(parameter.ParameterName, ParameterType.Single));
                    }
                }
                #endregion
            }
        }
    }

    return reportParameterList;
}

**Updates: The code snippet above provides getting the parameters by casting the InfoObject into CrystalDecisions.Enterprise.Desktop.Report, which is cleaner IMHO ;)

Unfortunately that we are not able to access the prompts / parameters using the same way for webi (web intelligence) report, the same properties are not available for webi :|

Advertisements