How to pass a record from Form to the Dialog and run an SSRS Report

Hello learners!

Let’s start learning the concept of sending a form record to a dialog using a “dialog” axclass and making sure to filter the record before sending the parameters to an ssrs report.


Article content

Here we have a scenario where each transfer order in “inventtransferorder” form, has transfer lines (showing the details of that particular transfer order). We have a custom table named as TransferOrderSackDetail which is linked to the inventtransfertable and inventtransferline table, the purpose of this table is basically to get the details of items/products, in a transfer order, placed in each sack. We have fields like transferid, sackid, itemid, qty, and so on.

The ssrs report we are creating here will give sackid based filtered data, for that we will open a particular transfer order, then use a dialog class to make a sackid lookup, then use controller class to send the selected sackid to the report’s parameter.

Step 01: Create 2 Temporary Tables

Create 2 temporary tables, one for header data and the other one for the line details.

For header, we have TOSackWiseHeaderTmp with fields such as CompanyName, CompanyLogo, TransferOrderNumber, TransferStatus, LocationNameFrom, LocationNameTo, ShipmentDate, Comment, DriverName, SealNumber, VehicleNumber, VerfiedBy. For Lines we have TOSackWiseLinesTmp with fields TransferId, SackId, Qty, ItemId, ItemName.

Both tables have tabletype property set to TempDB.

Step 02: Create a contract class

We are taking sackid as report parameter.

[DataContractAttribute]

public class TOSackWiseContract

{

str sackid;

[DataMemberAttribute(identifierStr(SackId))]

public str parmSackId(str _sackid = sackid)

{

sackid = _sackid;

return sackid;

}

public static TOSackwiseContract construct()

{

return new TOSackwiseContract();

}

}

Step 03: Create a DP Class

Here, RDP class is providing data, fetching it from a custom table and custom fields of some default tables, to the report. In this case, the custom table being used here is TransferOrderSackDetail and the default table InventTransferTable has following custom fields: Comments, DriverName, SealNumber, VehicleNumber, VerifiedBy. So, don’t get confused if it doesn’t work.

[SRSReportParameterAttribute(classStr(TOSackWiseContract))]

public class ITOSackWiseDP extends SrsReportDataProviderPreProcessTempDB

{

TOSackWiseHeaderTmp TransferOutHeaderTmp;

TOSackWiseLinesTmp TransferOutLinesTmp;

Args parmArgs;

/// <summary>

///

/// </summary>

/// <returns></returns>

[SRSReportDataSetAttribute(tablestr(‘TOSackWiseHeaderTmp’))]

public TOSackWiseHeaderTmp getTransferOutHeaderTmp()

{

select * from TransferOutHeaderTmp;

return TransferOutHeaderTmp;

}

/// <summary>

///

/// </summary>

/// <returns></returns>

[SRSReportDataSetAttribute(tablestr(‘TOSackWiseLinesTmp’))]

public TOSackWiseLinesTmp getTransferOutLinesTmp()

{

select * from TransferOutLinesTmp;

return TransferOutLinesTmp;

}

/// <summary>

///

/// </summary>

public void processReport()

{

str parmsackidVal;

TOSackWiseContract contract;

InventTransferTable inventTransferTable;

InventTransferLine inventTransferLine;

InventTransferId transferid;

CompanyInfo compInfo;

TransferOrderSackDetail TOsackdetail;

contract = this.parmDataContract() as TOSackWiseContract;

parmSackIdVal = contract.parmSackId();

select firstonly1 InventTransferId from TOsackdetail

where TOsackdetail.SackId == parmsackidVal;

transferid = TOsackdetail.inventtransferid;

compInfo = CompanyInfo::find();

TransferOutHeaderTmp.CompanyName = compInfo.name();

TransferOutHeaderTmp.CompanyLogo = FormLetter::companyLogo();

select firstOnly TransferId, ShipDate, TransferStatus, InventLocationIdTo, InventLocationIdFrom, Comments, DriverName, SealNumber, VehicleNumber, VerifiedBy from inventTransferTable where inventTransferTable.transferId == transferid;

TransferOutHeaderTmp.TransferOrderNumber = inventTransferTable.TransferId;

TransferOutHeaderTmp.ShipmentDate = this.getShipDate(inventTransferTable.TransferId);

TransferOutHeaderTmp.TransferStatus = inventTransferTable.TransferStatus;

TransferOutHeaderTmp.LocationNameFrom = InventLocation::find(inventTransferTable.InventLocationIdFrom).Name;

TransferOutHeaderTmp.LocationNameTo = InventLocation::find(inventTransferTable.InventLocationIdTo).Name;

TransferOutHeaderTmp.Comments = inventTransferTable.Comments;

TransferOutHeaderTmp.DriverName = inventTransferTable.DriverName;

TransferOutHeaderTmp.SealNumber = inventTransferTable.SealNumber;

TransferOutHeaderTmp.VehicleNumber = inventTransferTable.VehicleNumber;

TransferOutHeaderTmp.VerifiedBy = inventTransferTable.VerifiedBy;

TransferOutHeaderTmp.insert();

while select inventtransferid, SackId, qty, itemid from TOsackdetail where TOsackdetail.InventTransferId == transferid && TOsackdetail.SackId == parmsackIdval

{

TransferOutLinesTmp.InventTransferId = TOsackdetail.InventTransferId;

TransferOutLinesTmp.SackId = TOsackdetail.SackId;

TransferOutLinesTmp.ItemId = TOsackdetail.ItemId;

TransferOutLinesTmp.Itemname = this.getitemname(TOsackdetail.ItemId);

TransferOutLinesTmp.Qty = TOsackdetail.Qty;

TransferOutLinesTmp.insert();

}

}

private TransDate getShipDate(InventTransFerId _transferOrderNumber)

{

InventTransferJour InventTransferJour;

select firstonly TransDate from InventTransferJour

order by InventTransferJour.TransDate desc

where InventTransferJour.transferId == _transferOrderNumber

&& InventTransferJour.UpdateType == InventTransferUpdateType::Shipment;

return InventTransferJour.TransDate;

}

private str getItemName(ItemId _itemid)

{

str itemname;

InventTable inventtable;

select InventTable where InventTable.itemid == _itemid;

itemname = InventTable.itemname();

return itemname;

}

}

Step 04: Create and design Report


Article content
Report Components


Article content
Report Design

Step 05: Create a Controller Class

This controller class will take arguments (sackid as parameter to the report) from the dialog class that will be discussed in Step 07.

class TOSackWiseControllerClass extends SrsReportRunController

{

public static void main(args _args)

{

tosackwisecontract contract;

TOSackWiseControllerClass controller = new

TOSackWiseControllerClass();

common record;

formdatasource ds;

controller.parmreportname(ssrsreportstr(TOSackWiseReport, report));

controller.parmargs(_args);

controller.parmshowdialog(false);

controller.startoperation();

}

void prepromptmodifycontract()

{

tosackwisecontract contract;

string20 sackId;

sackId = this.parmargs().parm();

contract = this.parmreportcontract().parmrdpcontract() as tosackwisecontract;

if (contract)

{

contract.parmsackid(sackId);

}

}

}

Step 06: Create a Menu Item for this Controller

We are creating a menu item named as TOSackWiseReportMI for our controller class TOSackWiseControllerClass, select the object property as class, select the object name as controller class name of your report and set a label, here it is “Sack Wise Detail Report”.


Menu Item Properties
Menu Item Properties

Step 07: Create a Dialog Class

In this class, we are filtering the TransferOrderSackDetail table using TransferId from the InventTransferTable (currently opened transfer order), and creating a lookup field of SackId in our dialog. The run method takes the selected SackId and sends it to the controller class for the report to process.

class TOSackWiseDialog extends RunBase

{

TransferOrderSackDetail TOSackDetail;

Inventtransfertable transfertable;

InventTransferId transferid;

String20 sackid;

DialogField fieldSackId, fieldTransferId;

public container pack()

{

return conNull();

}

public boolean unpack(container _packedClass)

{

return true;

}

Object Dialog()

{

Dialog dialog;

dialog = super();

dialog.caption(“Select SackId”);

fieldTransferId = dialog.addField(extendedTypeStr(InventTransferId), “TransferId”);

fieldTransferId.value(transferId); // Set the transferId

fieldTransferId.fieldControl().enabled(false);

fieldSackId = dialog.addField(extendedTypeStr(String20), ‘SackId’);

fieldSackId.fieldControl().mandatory(true);

fieldSackId.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(TOSackWiseDialog, SackIdlookup), this);

return dialog;

}

public boolean getFromDialog()

{

sackId = fieldSackId.value();

return super();

}

public void setTransferId(Args _args)

{

InventTransferLine inventTransferLine;

if (_args && args.record() && args.record() is InventTransferLine)

{

inventTransferLine = _args.record();

transferId = inventTransferLine.TransferId; // Get the transferId from the selected record

}

}

public void sackIdLookup(FormControl _formControl)

{

Query query = new Query();

QueryBuildDataSource qbds;

qbds = query.addDataSource(tableNum(TransferOrderSackDetail));

qbds.addRange(fieldNum(TransferOrderSackDetail, inventTransferId)).value(SysQuery::value(transferId));

qbds.addGroupByField(fieldNum(TransferOrderSackDetail, sackid));

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(TransferOrderSackDetail), _formControl);

sysTableLookup.addLookupfield(fieldNum(TransferOrderSackDetail, SackId));

sysTableLookup.parmQuery(query);

sysTableLookup.performFormLookup();

}

public void run()

{

if (!sackId)

{

throw error(“Please select a Sack ID.”);

}

Args args = new Args();

args.name(“TOSackwisereportmi”);

args.parm(sackId);

new MenuFunction(args.name(), MenuItemType::Output).run(args);

}

}

step 08: create an extension of inventtransferorders form

Now, an extension of InventTransferOrders is required. We are adding a button in InquiriesButtonGroup in our ShipmentTab


Article content
Form Extension


Article content
TOSackWiseDialogBtn on Form Extension

Copy the button’s OnClicked event handler and create an extension class for this form.


Article content
OnClicked Event Handler

[ExtensionOf(formstr(InventTransferOrders))]

internal final class InventTransferOrder_Extension

{

/// <summary>

///

/// </summary>

/// <param name=”sender”></param>

/// <param name=”e”></param>

[FormControlEventHandler(formControlStr(InventTransferOrders, TOSackWiseDialogBtn), FormControlEventType::Clicked)]

public static void TOSackWiseDialogBtn_OnClicked(FormControl sender, FormControlEventArgs e)

{

Args args = new Args();

InventTransferLine inventTransferLine;

FormDataSource transferLineDataSource = sender.formRun().dataSource(formDataSourceStr(InventTransferOrders, InventTransferLine));

inventTransferLine = transferLineDataSource.cursor();

if (!inventTransferLine)

{

throw error(“Please select a transfer line.”);

}

TOSackWiseDialog dialog = new TOSackWiseDialog();

args.record(inventTransferLine);

dialog.setTransferId(args);

if (dialog.prompt())

{

dialog.run();

}

}

}

Conclusion

By following all these steps carefully, you’ll be able to pass a record from Form to the Dialog and run your SSRS Report successfully.


Article content
dialog for sackid lookup


Article content
Report output



Dua e Fatima

Data Engineer & Analyst @ Ideas Pvt. Ltd. || MS - Computer science & Information Technology (CSIT) || BE - Computer System Engineer (CS)

1mo

great.

Like
Reply
Muhammad Umer

Founder @ Devairo | Smart AI & Automation Solutions | Helping Businesses Grow 10x Faster | Let’s Elevate Your Business Today!

2mo

Good Start, Syeda Alishba Nasir

Like
Reply
Maheen Mukhtar

Laravel | PHP | SQL | SQA | Full Stack Development

2mo

Love this insight

Like
Reply

To view or add a comment, sign in

More articles by Syeda Alishba Nasir

Insights from the community

Others also viewed

Explore topics