Display method in OnHand form – D365FO

Adding a display method is generally straightforward, but implementing it on the OnHand form can be challenging since the buffers consistently return empty values.

For example, the following code snippet always results in an empty _inventSum buffer:

display Qty MyDisplayMethod(InventSum _inventSum)
{
InventSum inventSum;
FormDataSource InventSum_ds = _inventSum.datasource();
FormDataSource InventDim_ds = InventSum_ds.formRun().dataSource(“InventDim”);

return InventSum.MyCustomMethod(_inventSum, InventDim_ds);
}

Recently I came across this challenge and found another approach to handle this.

public display Notes myDisplayMethod(InventSum _inventSum)
{
InventDim inventDimLoc;
InventSum inventSumLoc;

FormObjectSet formObjectSet = this.formRun().dataSource(formDataSourceStr(InventOnhandItem, InventDim));
FormDataSource inventDim_fds = formObjectSet as FormDataSource;
Common InventDimJoined = formJoinedRecord(_inventSum, inventDim_fds);

inventDimLoc = InventDimJoined as InventDim;

select firstonly inventSumLoc
where inventSumLoc.ItemId == _inventSum.ItemId
&& inventSumLoc.InventDimension1 == inventDimLoc.InventDimension1;

// Rest of the logic to fetch necessary records using the above buffer ‘inventSumLoc’
}

FormObjectSet – another option to access the functionality when working with form datasources.

FormJoinedRecord -a function in FormDataSource object to access a joined record from a related table when working with multiple data sources on a form, allowing to retrieve data from a linked table directly within the current record context on the form. 

Though this code looks simple, it took 2 days for me to crack the challenge with ‘OnHandItem’ form.

Happy learning!!!!

Original Post https://anithasantosh.wordpress.com/2025/02/18/display-method-in-onhand-form-d365fo/

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *