How to Add Report Dynamic Parameter to DDSP
Take a look at the Inventory journal lines report. It can be open from Project management and accounting -> Journals -> Item.
This report has a dynamic parameter defined by the InventJournalTrans query. We can select values for various ranges in the Records to include tab page on the report dialog form by clicking the Filter button as shown on the picture below.
In the query browser form we can also add additional ranges on a field from any table that is a data source in the query, or it is related to a data source in the query. That is why this parameter is called dynamic parameter.
Note that the value of a range is not necessary a fixed value, it can also be a set of values, or a value with wildcards. It is hard to parse query ranges and to assume what would be specific needs for a particular report.
Take a look at the report custom DSP class with the overridden addParameters() method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
class DocInventJournalTransTransferDSP extends DocDataSourceProviderSrsReporting { // Global variables to store Dynamic parameter values (i.e. Dynamics query ranges). ItemId itemId; InventJournalId journalId; public ClassDescription description() { return 'InventJournalTrans.Report DSP'; } protected void preRunGenerateDS() { super(); // TODO: Check if you need to include display methods for ALL data sources in the query. //this.parmParams().parmIncludeDisplayMethodsInDs(true); // It's false by default. // NOTE: This can affect the performance. Rather override and use the addAdditionalDataFieldsForQueryRecord // method to add particular display methods. } // This is an overridden method that enables you to append additional data // to the Parameters data section of the report DDSP. protected void addParameters(DocXmlRecordBuilder _recordBuilderParameters) { super(_recordBuilderParameters); // We will add dynamics parameter values in the Parameters data section of DDSP. this.getQueryRanges(); _recordBuilderParameters.addCalculatedRecord('DynamicParameter'); _recordBuilderParameters.addCalculatedField('JournalId', journalId); _recordBuilderParameters.addCalculatedField('ItemId', itemId); } private void getQueryRanges() { List qbrList; ListEnumerator qbrListEnum; QueryBuildRange qbr; info('*** Dynamic parameter query ranges:'); qbrList = this.getSrsReportFirstDynamicQueryRanges(); if (qbrList) { qbrListEnum = qbrList.getEnumerator(); while (qbrListEnum.moveNext()) { qbr = qbrListEnum.current(); str qbrFieldName = qbr.fieldName(); info(strFmt('%1: %2', qbrFieldName, qbr.value())); switch (qbrFieldName) { case fieldStr(InventJournalTrans, ItemId): itemId = qbr.value(); break; case fieldStr(InventJournalTrans, JournalId): if (qbr.table() == tableNum(InventJournalTrans)) { journalId = qbr.value(); } break; // TODO: Get the rest of the ranges here. // NOTE: Non-string values have to be converted first, e.g.: //int intValue = DocGlobalHelper::getIntValueFromQueryBuildRange(qbr); //int64 int64Value = DocGlobalHelper::getInt64ValueFromQueryBuildRange(qbr); //date dateValue = DocGlobalHelper::getDateValueFromQueryBuildRange(qbr); //real realValue = DocGlobalHelper::getRealValueFromQueryBuildRange(qbr); //utcdatetime utcDateTimeValue = DocGlobalHelper::getUtcDateTimeValueFromQueryBuildRange(qbr); } } } } // This is an overridden method that enables you to add additional data to a report data source // which is an AX query, without changing the query itself. You can also add display method // to any of data source tables from the query. protected void addAdditionalDataFieldsForQueryRecord(DocXmlRecord _addingRecord, Common _common, QueryBuildDataSource _qbds) { InventJournalTrans currentInventJournalTrans; if (_qbds.table() == tableNum(InventJournalTrans)) { currentInventJournalTrans = _common; // TODO: Add new fields related to InventJournalTrans. _addingRecord.addDisplayMethod(tableMethodStr(InventJournalTrans, itemName)); } // TODO: Add additional data for each data source in the query. } // This is an overridden method that enables you to append additional data // to the Main data section of the report DDSP. protected void generateXmlDataSource(DocXmlRecordBuilder _recordBuilder) { boolean showLog; JournalError journalError; super(_recordBuilder); // After super() is executed, the Main data section of the report DDSP is already built. // Now we want to append additional data - Journal error message // if the ShowLog ('Print log') parameter is set to True. // Iterate through all report parameters. info('*** Report parameters (but not from dynamic query)'); MapEnumerator mapEnumerator = this.getParameters().getEnumerator(); while (mapEnumerator.moveNext()) { str reportParameterName = mapEnumerator.currentKey(); SRSReportParameter reportParameter = mapEnumerator.currentValue(); info(strFmt('%1: %2', reportParameterName, reportParameter.getValueTyped())); if (reportParameterName == 'ShowLog') { showLog = reportParameter.getValueTyped(); } } // We need to add journal error in a custom way, since adding a data field // of type container to RecordBuilder is not supported out-of-the-box. if (showLog) { _recordBuilder.goToTopRecord(); while select journalError where journalError.RefTableId == tableNum(InventJournalTable) && journalError.JournalId == journalId { _recordBuilder.addRecordWithAllFieldsExcept(journalError, [ fieldStr(JournalError, Infolog), fieldStr(JournalError, InfologAction) ]); // TODO: Unpack the container in the proper way and add the wanted string as a calculated field. _recordBuilder.addCalculatedField('Infolog', con2Str(journalError.Infolog)); } } } } |
Besides that, we also iterated through the all report parameters and all dynamic parameter query ranges to print them to Screen. The Print log parameter needs a special treatment because it is not automatically added to the report data source.
In Docentric report setup we have to select this DSP class (DocInventJournalTransDSP) instead of the Default DSP class.
When we execute the report, we will get all report parameters and all dynamic parameter query ranges printed out to Screen.
You can also see how our custom logic in the DSP class has affected the report data source.
See also
How to Add Additional Data to a Query Based Report >>
Docentric Training for Writing Custom DSP Classes >>
How to Use Docentric AX APIs >>
Visual Studio Templates for DSP Classes >>