Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9730

Re: Read the Definition of dynamic Parameter-Fields via Code

$
0
0

Hi Michael,

 

That does help a lot... unfortunately you can't get the LOV SQL statement because it's dynamic, there are actually one SELECT Statement for each parameter, CR has to get the values to populate the drop down list and then append the filtering as each parameter value is entered.

 

There is no API to get into the list... other than getting the values....

 

If you want here's how to, and note the first routine is not public so if anythign changes you can't escalate a bug report:

 

public Boolean isParameterDynamic(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt, int iCnt, bool YorN)

{

    if (rpt.DataDefinition.ParameterFields[iCnt].Attributes != null && rpt.DataDefinition.ParameterFields[iCnt].Attributes.ContainsKey("IsDCP"))

    {

        Hashtable objAttributes = rpt.DataDefinition.ParameterFields[iCnt].Attributes;

        YorN = (Boolean)objAttributes["IsDCP"];

        return YorN;

    }

    return YorN;

}

 

Then to get the values as seen in the report:

 

    else

    {

        isParameterDynamic(rpt, 0, YorN);

        btnReportObjects.AppendText(paramfield.Name.ToString());

        if (YorN)

        {

            btnReportObjects.AppendText(": No Initial Value \n");

        }

        else

        {

            string myPrefix = paramfield.Description;

            btnReportObjects.AppendText(": Dynamic Cascading Parameter ( LOV )\nBased on field: " + paramfield.FormulaForm + "\n");

        }

    }

}

 

That is about all you can get with the API. No hook into the CR prompt UI.

 

So here's how you work around it.

 

Use Parameters in a Command Object and set the filtering accordingly.... same logic as what we are doing...

 

To Get/Set the Command SQL:

CrystalDecisions.ReportAppServer.DataDefModel.CommandTable newTbl = new CommandTable();
CrystalDecisions.ReportAppServer.DataDefModel.Table oldTbl1;

 

// This gets the SQL from the report

GroupPath gp = new GroupPath();
gp.FromString("");
string sql = String.Empty;
rptClientDoc.RowsetController.GetSQLStatement(gp, out sql);
//MessageBox.Show(sql.ToString());

 

rcd.DatabaseController.SetTableLocationEx(oldTbl1,newTbl1);
oldTbl1 =(CrystalDecisions.ReportAppServer.DataDefModel.Table) rcd.Database.Tables[0].Clone(true);
rcd.DatabaseController.SetTableLocationEx(oldTbl1, newTbl1);
//MessageBox.Show(sql.ToString());

 

// set the new SQL based on your parameters

newTbl1.ConnectionInfo = newConnInfo;
newTbl1.CommandText = "SELECT * from Orders"; // this is where you append the filtering to.
newTbl1.Name = "Orders";
newTbl1.Alias = "Orders";
rcd.DatabaseController.SetTableLocation(oldTbl1, newTbl1);

 

Create your own Parameter and set the filtering accordingly in the above SQL statement. But you also need to populaate the list...

 

Hope that clear

Don


Viewing all articles
Browse latest Browse all 9730

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>