Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to retrieve the SalesLine ItemID in SSRS Report parameter based on selected Line - x++

(4) ShareShare
ReportReport
Posted on by 233
Hello,
 
im developing a custom ssrs report, i need it to print data based on selected sales line itemid. so lets say i have a sales order with 3 sales lines, and i select the 1st row, it should get me the data based on the first row's itemid ,knowing that each row has a different itemID. i developed the Contract, controller and DP classes. after debugging the code, i found that in the  processReportParameters() method in the controller class, the buffer "contract" is always null, which is related to the contract class. when i try to print the report, its giving always error that "Something went wrong while generating the report. Please try again."
 
i would appreciate your help in my issue.
Thanks
[DataContractAttribute]
class ContractClasz
{
    private ItemId itemId;


    [DataMemberAttribute('ItemId')]
    public ItemId parmItemId(ItemId _itemId = itemId)
    {
        itemId = _itemId;
        return itemId;
    }

}
public class SalesControllerClasz extends SrsReportRunController
{
    protected void PrePromptModifyContract()
    {
        ContractClasz contract = this.parmReportContract().parmRdpContract();
        this.processReportParameters(contract);

    }
    void processReportParameters(ContractClasz _contract)
    {
        ContractClasz contract;
        SalesTable SalesTable;
        SalesLine SalesLine;

        if(this.parmArgs().record().TableId == tableNum(SalesLine))
        {
            if(this.parmArgs() && this.parmArgs().record())
            {
                contract = this.parmReportContract().parmRdpContract() as ContractClasz ;
                SalesLine = this.parmArgs().record();
            }
            _contract.parmItemId(SalesLine.ItemId);
          
        }
    }
    public static void main(Args _args)
    {
        SalesControllerClasz controller = new SalesControllerClasz();
        controller.parmArgs(_args);
        controller.parmReportName(ssrsReportStr(ReportTTT, Design));
        controller.startOperation();
    }

}
 
Categories:
  • Verified answer
    Aymen CHELBI Profile Picture
    344 on at
    How to retrieve the SalesLine ItemID in SSRS Report parameter based on selected Line - x++
    Hello, 
     

    Try modifying this part of the code as follows : 

     

    public class SalesControllerClasz extends SrsReportRunController
    {
        protected void PrePromptModifyContract()
        {
            ContractClasz contract = this.parmReportContract().parmRdpContract() as ContractClasz;

            if (!contract)
            {
                contract = new ContractClasz();
                this.parmReportContract().parmRdpContract(contract);
            }
            this.processReportParameters(contract);
        }
        void processReportParameters(ContractClasz _contract)
        {
            SalesLine salesLine;
            if (this.parmArgs() && this.parmArgs().record().TableId == tableNum(SalesLine))
            {
                salesLine = this.parmArgs().record() as SalesLine;
                if (salesLine)
                {
                    _contract.parmItemId(salesLine.ItemId);
                    // Ensure the contract is updated in the report contract
                    this.parmReportContract().parmRdpContract(_contract);
                }
            }
        }
        public static void main(Args _args)
        {
            SalesControllerClasz controller = new SalesControllerClasz();
            controller.parmArgs(_args);
            controller.parmReportName(ssrsReportStr(ReportTTT, Design));
            controller.startOperation();
        }
    }
     
  • Martin Dráb Profile Picture
    231,880 Most Valuable Professional on at
    How to retrieve the SalesLine ItemID in SSRS Report parameter based on selected Line - x++
    You need to use the debugger to find the actual exception.
     
    Your code in processReportParameters() is weird:
    • Whether contract variable is null or not isn't important, because you never use it for anything.
    • You're using the value of salesLine.ItemId even if you didn't populate salesLine variable.
    • You're using the value of this.parmArgs().record() before checking whether you have any Args at all. You need to change the order of the conditions.
    • You've declared salesTable variable, but you never use it.
  • Layan Jwei Profile Picture
    7,722 Super User 2025 Season 1 on at
    How to retrieve the SalesLine ItemID in SSRS Report parameter based on selected Line - x++
    Hi,
     
    When you debug, does it reach this line?
    contract = this.parmReportContract().parmRdpContract() as ContractClasz;
  • Suggested answer
    Vishal Tiwari Profile Picture
    393 on at
    How to retrieve the SalesLine ItemID in SSRS Report parameter based on selected Line - x++
    Hi,
     
     
    Contract Class Issue: Ensure your contract class has the correct DataMember attribute and is correctly initialized in the controller.
    Passing Parameters: The controller should correctly pass the selected SalesLine’s ItemId to the contract.
    processReportParameters() Issue: If the contract is null, check if it's properly assigned using parmRdpContract().
    DP Class Filtering: Ensure your DP class retrieves the contract and filters data based on ItemId.
    Menu Item Data Source: If your report is tied to a specific table, the menu item in the data source should point to the correct table.(check the form etc)
    Debugging: Add breakpoints in processReportParameters() and verify args.record() to confirm you're getting the selected SalesLine.
     
    Thank you!
     

    *If this resolved your issue, please mark it as "Verified" to assist others facing the same problem*

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,099 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,880 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans