Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

SSRS Class Controller and Class Data Provider passing value

(0) ShareShare
ReportReport
Posted on by 135

Hi everyone,

I have a report based in PurchTable and PurchLine and i want to select a record in AX and show in report only the selected one. I have a button and a method clicked:

-----------------------------------------------------------

void clicked()
{
PurchTable purchTableLocal;
Args args = new Args();

for(purchTableLocal = getFirstSelection(PurchaseTable_ds);
purchTableLocal;
purchTableLocal = PurchaseTable_ds.getNext())
{

args.parm(purchTableLocal.PurchId);

new MenuFunction(menuitemActionStr(VSSReportPedidos), MenuItemType::Action).run(args);
}

super();
}

(get the value correctly)

--------------------------------------------------------------------------------------------------------------------

I have the clas Controller, Contract and Data provider:

------------------------------------------------------------------------------------------------------------------

public void processReport()
{
PurchId purchId;
Query query;
PurchTable purchTable;
PurchLine purchLine;
VSSPedidosContractClass dataContract;//coge la query del runtime usando una query dinámica


query = this.parmQuery();// coge los parámetros pasados de runtime

dataContract = this.parmDataContract();//as VSSPedidosContractClass;

purchId = dataContract.parmPurchId();


if(purchId)
{

select purchTable
where purchTable.PurchId == purchId;

pedidosTemp.DeliveryDate = purchTable.DeliveryDate;
pedidosTemp.OrderAccount = purchTable.orderAccount;
pedidosTemp.PurchaseType = purchTable.purchaseType;
pedidosTemp.PurchIdPedido= purchTable.purchId;
pedidosTemp.PurchStatus = purchTable.purchStatus;
pedidosTemp.CurrencyCode = purchTable.CurrencyCode;


while select LineAmount, LineNumber, Name, purchId, PurchPrice, PurchQty, CurrencyCode from purchLine
where purchLine.PurchId == purchId
{

pedidosTemp.LineAmount = purchLine.LineAmount;
pedidosTemp.LineNumber = purchLine.LineNumber;
pedidosTemp.Name = purchLine.Name;
pedidosTemp.PurchIdLinea = purchLine.PurchId;
pedidosTemp.PurchPrice = purchLine.PurchPrice;
pedidosTemp.PurchQty = purchLine.PurchQty;
pedidosTemp.CurrencyCode = purchLine.CurrencyCode;

pedidosTemp.insert();
}

}
if(!purchId)
{

ttsBegin;
while select * from purchTable
{
pedidosTemp.DeliveryDate = purchTable.DeliveryDate;
pedidosTemp.OrderAccount = purchTable.orderAccount;
pedidosTemp.PurchaseType = purchTable.purchaseType;
pedidosTemp.PurchIdPedido= purchTable.purchId;
pedidosTemp.PurchStatus = purchTable.purchStatus;
pedidosTemp.CurrencyCode = purchTable.CurrencyCode;


while select * from purchLine
where purchLine.PurchId == purchTable.PurchId
{
pedidosTemp.LineAmount = purchLine.LineAmount;
pedidosTemp.LineNumber = purchLine.LineNumber;
pedidosTemp.Name = purchLine.Name;
pedidosTemp.PurchIdLinea = purchLine.PurchId;
pedidosTemp.PurchPrice = purchLine.PurchPrice;
pedidosTemp.PurchQty = purchLine.PurchQty;
pedidosTemp.CurrencyCode = purchLine.CurrencyCode;

pedidosTemp.insert();


}

}

ttsCommit;

}
}

(DON'T get the value correctly)

----------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------

[DataMemberAttribute("purchid")]
public purchid parmPurchId(PurchId _purchid = PurchId)
{

PurchId = _purchid;

return PurchId;
}

(get the value correctly)

----------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------

protected void preRunModifyContract()
{

VSSPedidosContractClass contract = contract as VSSPedidosContractClass;
contract.parmPurchId(args.parm());

super();
}

----------------------------------------------------------------------------------------------------------------------------------

public static client void main(Args _args)
{

//definir un nuevo objeto para la clase controller

VSSPedidosControllerClass controllerClass;
controllerClass =new VSSPedidosControllerClass();

//pasar el caller args al controller
controllerClass.parmArgs(_args);

//Definir el nombre del report y del diseño del mismo
controllerClass.parmReportName(ssrsReportStr(ReportPedidosUnaTabla, PrecisionDesign1));

//Ejecutar el report
controllerClass.runToScreen(); //Abrir informe sin ventana de diálogo

}

(get the value correctly)

-------------------------------------------------------------------------------------------------------------------------------------------

So, my problem is  PurchId don't reach Class Data Provider. I don't know if im doing something wrong, besides i put a break point in preRunModifyContract() and didn't stopped. So i tried put the code in method main:

public static client void main(Args _args)
{

VSSPedidosContractClass dataContract;

//definir un nuevo objeto para la clase controller
VSSPedidosControllerClass controllerClass;
controllerClass =new VSSPedidosControllerClass();

////////////////////////////////////////////////////////////////////
dataContract = new VSSPedidosContractClass();
dataContract.parmPurchId(_args.parm());
////////////////////////////////////////////////////////////////////


controllerClass.parmArgs(_args);

//Definir el nombre del report y del diseño del mismo
controllerClass.parmReportName(ssrsReportStr(ReportPedidosUnaTabla, PrecisionDesign1));


controllerClass.runToScreen(); //Abrir informe sin ventana de diálogo

}

(get the value correctly)

--------------------------------------------------------------------------------------------------------------------

I don't know what its wrong, am i forgetting somthing? i can't debug DataProvider class because of a problem with caches (error parameter RecId for preRun is missing). So i hope you can help me. 

Thanks.

*This post is locked for comments

  • MartaDiazVila Profile Picture
    MartaDiazVila 135 on at
    RE: SSRS Class Controller and Class Data Provider passing value

    Done, thanks.

  • Verified answer
    udaY-ch Profile Picture
    udaY-ch 4,624 on at
    RE: SSRS Class Controller and Class Data Provider passing value

    You should use ControllerClass.StartOperation. This will call the prerunModifyContract automatically.

    Also, If you dont want to show the dialog while opening the report, you can use controllerclass.showdialog(false)

  • MartaDiazVila Profile Picture
    MartaDiazVila 135 on at
    RE: SSRS Class Controller and Class Data Provider passing value
    class VSSPedidosControllerClass extends SrsReportRunController
    {
    }

    protected void preRunModifyContract()
    {
    
        VSSPedidosContractClass contract = this.parmReportContract().parmRdpContract();
        contract.parmPurchId(args.parm());
    
        super();
    }

    public static client void main(Args _args)
    {
    
        VSSPedidosControllerClass controllerClass;
        controllerClass =new VSSPedidosControllerClass();
    
    
        controllerClass.parmArgs(_args);
    
        controllerClass.parmReportName(ssrsReportStr(ReportPedidosUnaTabla, PrecisionDesign1));
        controllerClass.preRunModifyContract();
    
        controllerClass.runToScreen(); 
    
    
    }


    If i don't call it, doesn't work :(

  • Martin Dráb Profile Picture
    Martin Dráb 231,436 Most Valuable Professional on at
    RE: SSRS Class Controller and Class Data Provider passing value

    You shouldn't call it by yourself. Can you please show us the complete code of your controller class?

  • MartaDiazVila Profile Picture
    MartaDiazVila 135 on at
    RE: SSRS Class Controller and Class Data Provider passing value

    It's not working, i think PreRunModdifyContract it's not running.

    UPDATE: I call preRunModifyContract from main, now it's finally working, thanks.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,436 Most Valuable Professional on at
    RE: SSRS Class Controller and Class Data Provider passing value

    Oh, now I've noticed that your code there makes no sense at all. You do this:

    VSSPedidosContractClass contract = contract as VSSPedidosContractClass;

    Which means that you create a new, empty variable called contract and you set it's value to... the new, empty variable called contract. It's the same as not initializing it at all.

    Then you call this:

    contract.parmPurchId(args.parm());

    But because contract is null, the call must always throw an exception. Didn't you notice it?

    Try this code instead:

    VSSPedidosControllerClass contract = this.parmReportContract().parmRdpContract();
    contract.parmPurchId(args.parm());
  • MartaDiazVila Profile Picture
    MartaDiazVila 135 on at
    RE: SSRS Class Controller and Class Data Provider passing value

    "But you must update the contract object used by the controller"

    ok, don't know how or where do it. According to what you tell me, it seems to be my problem.

  • Martin Dráb Profile Picture
    Martin Dráb 231,436 Most Valuable Professional on at
    RE: SSRS Class Controller and Class Data Provider passing value

    No, the initializing logic doesn't belong to the data provider class. The provider is called much later in the process, when SSRS is printing the report. You never call the provider class by yourself.

    The logic belongs to the controller class. It's what you already tried to do in contoller's preRunModifyContract() method, didn't you? There you get the caller record and update the contract, which will be later passed to the data provider. But you must update the contract object used by the controller; I'm not sure if you do (that's why I asked in my previous reply).

  • MartaDiazVila Profile Picture
    MartaDiazVila 135 on at
    RE: SSRS Class Controller and Class Data Provider passing value

    Hi Martin, thanks for your answer,

    The "for" its because in the future i want to select more than one record but for now im trying just one.

    On the other hand, if i drag the menuItem (its not a output, its an action) to the form, then where i call the record? in Data provider class? that simple?

    About your other answer, maybe there is the error, once in controller i don't know how reach data provider. I don't know if you know what i mean. 

    I think the sequence of the record is as follows:

    Clicked()-->Controller-->Contract(preRun)-->Controller-->DataProvider-->Contract(parm)-->DataProvider-->report

    Its that right?? In case it is correct, my problem is i dont know the step "Controller-->DataProvider" (passing value between the classes i mean). I thought with the code on "preRunModifyContract()" i will pass somehow the record to DataProvider, and call args.record() there, like i show. But i dont know really, im a little bit loss right now.

  • Martin Dráb Profile Picture
    Martin Dráb 231,436 Most Valuable Professional on at
    RE: SSRS Class Controller and Class Data Provider passing value

    How do you fill in the contract variable that you use in preRunModifyContract()? Are you sure it points to the right object?

    Also note that your last code snippets fills in dataContract object but never uses it for anything.

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... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans