Step-by-Step Guide to Implementing a JumpRef Method in X++
Ujjawal Tiwari
"Skilled Professional in Microsoft Dynamics 365 F&O Development, Tech Consulting, Full Stack Dev, Data Analysis, DevOps. Proficient in Azure, Power BI, Power Apps, Digital Marketing, GitHub, PHP, C# and X++"
Introduction
In this blog, we will walk through the implementation of a jumpRef method in X++, which facilitates navigation and record handling in Microsoft Dynamics 365 Finance and Operations (D365FO). For demonstration purposes, we will use fictional data source names, table names, fields, and form names.
Scenario Overview
We want to create a jumpRef method that:
Additionally, we’ll customize the init method in the target form to handle parameters passed from the jumpRef method.
Step-by-Step Implementation
1. Create a Data Source for the Main Table
Add a table data source to your form to represent the primary table. For this example, we will use MainTable as our table and MainTable_ds as the data source.
领英推荐
2. Write the jumpRef Method
Below is the implementation of the jumpRef method:
public void jumpRef()
{
MainTable mainTableRecord = MainTable_ds.cursor();
DetailTable detailTableRecord;
CategoryTable categoryTable;
ParentTable parentRecord = ParentTable_ds.cursor();
if (mainTableRecord)
{
ttsBegin;
if (parentRecord)
{
// Check for existing records
select firstonly RecId from detailTableRecord
where detailTableRecord.ReferenceRecId == mainTableRecord.RecId
&& detailTableRecord.ParameterField == mainTableRecord.Parameter;
if (!detailTableRecord)
{
// Insert new records if none exist
while select categoryTable
where categoryTable.CategoryId == parentRecord.CategoryId
&& categoryTable.IsActive == NoYes::Yes
{
detailTableRecord.clear();
detailTableRecord.ReferenceRecId = mainTableRecord.RecId;
//ADD Your fields
detailTableRecord.insert();
}
}
}
ttsCommit;
// Open the details form
Args args = new Args();
args.name(formStr(DetailForm));
args.record(detailTableRecord);
args.parm(strFmt("%1|%2", mainTableRecord.RecId, mainTableRecord.Parameter));
new MenuFunction(formStr(DetailForm), MenuItemType::Display).run(args);
}
else
{
info("This field is not clickable under the current conditions.");
}
}
3. Update the init Method in the Target Form
The init method in DetailForm is updated to handle parameters passed from the jumpRef method:
public void init()
{
super();
Args args = this.args();
if (args)
{
DetailTable detailTableRecord = args.record();
if (args.parm())
{
container filterParams = str2con(args.parm(), '|');
RefRecId refRecId = conPeek(filterParams, 1);
str parameterField = conPeek(filterParams, 2);
QueryBuildDataSource qbds = DetailTable_ds.query().dataSourceTable(tableNum(DetailTable));
qbds.addRange(fieldNum(DetailTable, ReferenceRecId)).value(queryValue(refRecId));
qbds.addRange(fieldNum(DetailTable, ParameterField)).value(queryValue(parameterField));
DetailTable_ds.research(true);
}
else if (detailTableRecord)
{
DetailTable_ds.findRecord(detailTableRecord);
}
}
}
Conclusion
This implementation demonstrates how to effectively use the jumpRef method to navigate between forms while dynamically handling records. By following this step-by-step guide, you can customize and extend the functionality for various use cases in D365FO.