Deep dive into X++ SysOperation: Sending form multi-selected records in the contract.

In the YouTube video we are going to analyse a few wrong options to send form multi-selected records in the SysOperations data contract and to understand why they are not a good approach for making it in all the situations. Afterwards we are going to see the solution I would rather decide to implement. Of course you can go directly to the final solution if you want only the fish: My Solution. Or not watching the video at all and following this post instead.

Introduction

We want to make a process, using the Sys Operations Framework, to make something with the selected records of the FormDataSource of our form. (in our case the SalesTableListPage).

Considerations and “bad” approaches

If we go the straight way and we try to use directly the FormDataSource as a data member of our data contract (to avoid using for example a container and so, avoid looping the records twice), despite not having any build error, we are going to provoke an execution error:

This happens because the FormDataSource object is not a valid data member, check the MS documentation: Using Data Contracts in X++. If we want to skip that error we might want to remove the DataMember attribute of the parm method, so, as long as we fulfil it correctly it should work, shouldn’t it? the answer is yes and no. It will work only in Synchronous executions, but for example if you run it in batch, the actual Data Contract instance is going to be lost, and only the Data Members are going to arrive to the service.

Other “tricky” solution, as tables and views are supported as data members, could be to use the SalesTable as data member, and after that, in the service retrieve the table instance related FormDataSource, using the FormDataUtil::getFormDataSource(Common _common) mehthod. It would be something like that in the Service:

But with that, we are going to face the same issue, this code above will only work in Synch executions. If we run it in batch we can see how the FormDataSource instance related somehow with the SalesTable, it is going to be lost along the way too.

My approach

So, after all those tries, we have to resign and to create a container (with the RecIds for example) to be used to send the info to the service and ensure all the information arrives safely no matter the way it is executed. So the complete code would be:

IMPORTANT: If you are sending a large amount of RecIds then it’s a very bad idea to use the container, you should use a list instead. Here I explain how.

Data Contract
Service
Controller

Note how I am retrieving the FormDataSource from the caller record instead of using the:

FormRun callerFormRun = this.parmArgs().caller();

callerFormRun.dataSource(formDataSourceStr(SalesTableListPage, SalesTable));

I make it in purpose so I can retrieve the SalesTable FormDataSource no matter what form is calling. For example, adding the menu item reference to the SalesTable form would also work without having to modify the code. And there are no problems of using it because, obviously, that controller logic is going to be executed always in Synch mode, as it is done prior the SysOperation execution itself.


One thought on “Deep dive into X++ SysOperation: Sending form multi-selected records in the contract.

Leave a comment