Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Object reference not set to an instance of an object (report)

(0) ShareShare
ReportReport
Posted on by 312
Hi,
 
I'm newbie in creating report in D365FO.
When create a report, with parameter are From date and To Date in its dialog, I created these objects:
1. Temp table (XX_Report1Tmp)
2. SSRSReport  named /XX_Detail/ (and deployed)
3. Contract class = XX_RptContract
   
[DataContractAttribute, SysOperationAlwaysInitializeAttribute,SysOperationContractProcessing(classStr(XX_RptUIBuilder))]class XX_RptContract extends SrsReportRdlDataContract{    TransDate   fromDate, toDate;    private const str ParameterFromDate = 'FromDate';    private const str ParameterToDate = 'ToDate';    public boolean validate()    {        boolean isValid = super();        fromDate = this.getValue(ParameterFromDate);        toDate = this.getValue(ParameterToDate);                if (!fromDate)        {            isValid = checkFailed(/@SYS97591/);        }        if (!toDate)        {            isValid = checkFailed(/@SYS97592/);        }        if (fromDate && toDate)        {            if (fromDate > toDate)            {                isValid = checkFailed(/@SYS120590/);            }        }        return isValid;    }}
 
4.  UIBuilder Class = XX_RptUIBuilder (and put the name in the Contract class)
 
[    SrsReportNameAttribute('XX_Detail.Report'),    SysOperationContractProcessingAttribute(classstr(XX_RptUIBuilder), SysOperationDataContractProcessingMode::CreateUIBuilderForRootContractOnly)]class XX_RptUIBuilder extends SrsReportDataContractUIBuilder{    XX_RptContract       rptContract;    DialogField          dlgFrom, dlgTo;    private const str ParameterFromDate = 'FromDate';    private const str ParameterToDate = 'ToDate';    public void build()    {        Dialog                  dialogLocal;        dialogLocal = this.dialog();        rptContract = this.getRdlContractInfo().dataContractObject() as XX_RptContract;                        dialogLocal.addGroup(/@SYS183857/);        dlgFrom = dialogLocal.addFieldValue(extendedTypeStr(FromDate), DatetimeUtil::date(rptContract.getValue(ParameterFromDate)), /@SYS5209/,//);        dlgTo = dialogLocal.addFieldValue(extendedTypeStr(ToDate), DatetimeUtil::date(rptContract.getValue(ParameterToDate)), /@SYS14656/);    }    /// <summary>    ///    Transfers data from the dialog into the data contract object.    /// </summary>    public void getFromDialog()    {        rptContract.setValue(ParameterFromDate, DateTimeUtil::newDateTime(dlgFrom.value(), 0));        rptContract.setValue(ParameterToDate, DateTimeUtil::newDateTime(dlgTo.value(), 0));    }}
 
5. Controller class
 
class XX_RptController extends SrsReportRunController{    public static void main(Args _args)    {        XX_RptController controller = new XX_RptController();                controller.parmArgs(_args);        controller.parmReportName(ssrsReportStr(XX_Detail, AutoDesign));        controller.parmShowDialog(true);        controller.startOperation();    }}
 
 
But I always getting error /Object reference not set to an instance of an object/, hit in UIBuilder class on this line /rptContract = this.getRdlContractInfo().dataContractObject() as  XX_RptContract;/. May I know what I've been missed ? 
 
Thanks.
 
 
  • Martin Dráb Profile Picture
    Martin Dráb 230,488 Most Valuable Professional on at
    Object reference not set to an instance of an object (report)
    There is a bug causing problems with answer verification.
    But it worked for me in this case (I'm a super user, so I can do in on your behalf).
  • Teevo Profile Picture
    Teevo 312 on at
    Object reference not set to an instance of an object (report)
    Thanks,
     
    I want to close this thread. Somehow it always "processing". Can someone help. Maybe to put remark on 1st reply.
    Thanks
  • Martin Dráb Profile Picture
    Martin Dráb 230,488 Most Valuable Professional on at
    Object reference not set to an instance of an object (report)
    The reason why I didn't mention it before is that you don't need to do anything for it to be used.You'll just define a data contract and associate with the RDP (through SrsReportParameterAttribute) and the (SysOperation) framework will automatically use the default UI build to generate the UI. If the generated dialog meets your needs, you don't have to worry about UI builder classes at all.
  • Teevo Profile Picture
    Teevo 312 on at
    Object reference not set to an instance of an object (report)
    Ok, you have mentioned this on the first reply "use the dialog generated automatically for you from the contract" , but should we stated that "SysOperationAutomaticUIBuilder" somewhere ? 
    Because as you are mentioned, there is no need to have (create) custom UIBuilder class, and this "SysOperationAutomaticUIBuilder" is only mentioned when we extend it at the custom UI builder. Does it mean we still create but leave it blank ? Just the <UIBuilder name> extends SysOperationAutomaticUIBuilder, then super().
     
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,488 Most Valuable Professional on at
    Object reference not set to an instance of an object (report)
    Typically, you don't define any custom UI builder class and you let the default one (SysOperationAutomaticUIBuilder) to generate the dialog for you. Only when you want change the behavior, you'll create a UI builder class extending SysOperationAutomaticUIBuilder and you override the methods you want to change. Whether you want to change postBuild(), postRun() or something else depends on what you're trying to achieve. postBuild() is called before the dialog form is even executed and postRun() just after showing the dialog.
  • Teevo Profile Picture
    Teevo 312 on at
    Object reference not set to an instance of an object (report)
    Hi Martin,
     
    May I know as well, how is the common UIBuilder class for RDP looks like ? Still considering I want to have parameter From Date and To Date.
     
    Reason is I'm still confuse because some of the sample is having PostBuild() and some is having PostRun(). There is one blog I noticed with PostBuild() then I saw its PostRun() which contain only super(), but he remarks and commented it, means it will do nothing. One thing in common is they have overwrite method Build() which contain the addition of DialogFied FromDate and ToDate. So basically what method should it important and mandatory ?
     
    My contract class now is similar like the one you've advice, if not the exact same. Only different the header which is I put the name of my UIBuilder class like this :
         [DataContractAttribute,
                SysOperationContractProcessingAttribute(classstr(XX_RptUIBuilderI))
         ]
    The rest is same.
     
     
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,488 Most Valuable Professional on at
    Object reference not set to an instance of an object (report)
    AssetBasis is a different type of report, therefore the implementation is very different. It uses a query, not an RDP class, as the data source.
  • Teevo Profile Picture
    Teevo 312 on at
    Object reference not set to an instance of an object (report)
    Hi Martin,
     
    Noted, I will try.
    About the RDP class, actually I have, sorry forgot to put in here, but also because the error seems between Contract class and UIBuilder class, so I only put those 2 classes plus the controller class.
    My RDPclass is like this :
    [SrsReportParameterAttribute(classStr(XX_RptContract))]
    class XX_RptRDP extends SrsReportDataProviderPreProcessTempDB
    {
        XX_Report1Tmp  detailRptTmp;
        Amount      TotalInvoiceAmt, TotalSettledAmt, BalanceAmt;
    
    
        [SrsReportDataSet(tableStr(XX_Report1Tmp))]
        public XX_Report1Tmp getXX_Report1Tmp()
        {
            select detailRptTmp;
            return detailRptTmp;
        }
    
        public void processReport()
        {
            XX_RptContract contract = this.parmDataContract() as XX_RptContract;
            TransDate fromDate = contract.parmFromDate();
            TransDate toDate = contract.parmToDate();
    
            .
    	 . <process inserting temp table>
            .
            
    
        }
    
    }
    
     
     
    About all these classes, expecially the UIBuilder class, actually it is following 1 standard report named "AssetBasis"
     
    I believe those are the objects related to this report "AssetBasis", right ? (those without suffix _IN)
     
     
    Anyway, I will try to change my UIBuilder first, as per your advice. May I know also, what is the different with RDL ? since you're mentioned "you also try to use a RDL contract instead"Thanks.
     
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,488 Most Valuable Professional on at
    Object reference not set to an instance of an object (report)
    What data source do you want to use for your report?
     
    You mentioned a temporary table, therefore your intention seems to be using a report data provider (RDP) class, but you don't have it yet (and you also try to use a RDL contract instead). When you create the RDP, decorate it with SRSReportParameter attribute and use your contract class name there. Then use the RDP class as the data source of your report. SSRS will then know which parameters to use and they'll add it to the report.
     
    The contract class should look somehow like this:
    [
        DataContract,
        SysOperationAlwaysInitialize
    ]
    public class XX_RptContract implements SysOperationValidatable
    {
        FromDate fromDate
        ToDate toDate;
        
        [DataMember]
        public FromDate parmFromDate(FromDate _fromDate = fromDate)
        {
            fromDate = _fromDate;
            return fromDate;
        }
        
        [DataMember]
        public ToDate parmToDate(ToDate _toDate = toDate)
        {
            toDate = _toDate;
            return toDate;
        }
        
        public boolean validate()
        {
            boolean isValid = true;
        
            if (!fromDate)
            {
                isValid = checkFailed("@SYS97591");
            }
            
            if (!toDate)
            {
                isValid = checkFailed("@SYS97592")
            }
            
            if (isValid && fromDate > toDate)
            {
                isValid = checkFailed("@SYS120590");
            }
            
            return isValid;
        }
    }
    Your UI builder class doesn't seem to be doing anything interesting, therefore you can throw it away and use the dialog generated automatically for you from the contract. If you find a reason for creating a UI builder, get the contract there by calling this.dataContractObject().
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,791 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,488 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans